Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:66664 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 48818 invoked from network); 16 Mar 2013 19:34:45 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Mar 2013 19:34:45 -0000 Authentication-Results: pb1.pair.com smtp.mail=dnl.rlnd@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=dnl.rlnd@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.47 as permitted sender) X-PHP-List-Original-Sender: dnl.rlnd@gmail.com X-Host-Fingerprint: 209.85.214.47 mail-bk0-f47.google.com Received: from [209.85.214.47] ([209.85.214.47:35163] helo=mail-bk0-f47.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F5/C5-08095-359C4415 for ; Sat, 16 Mar 2013 14:34:44 -0500 Received: by mail-bk0-f47.google.com with SMTP id jc3so1942785bkc.34 for ; Sat, 16 Mar 2013 12:34:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:from:date:message-id:subject:to :content-type; bh=XbpSCDHjlXqrtFUfCb7BaG43ijsQrtunMvhUxpfIAvk=; b=DoVfeWvUM0i+f7QUN/4LzLu5y+dgMeKYEEKUGc/dOrQdzXGnjfw7nxztv1Nk8GTXEy VhBl2YCGyBr9Ub6szUF8aFBfhFBz8OG5Qu9IgUwQ9bvCJKrmHnzeVh1eCilZsKzWEK6T Mrxp8hxlJUZ2uduFgoTyIrrdJKsg5KpY5PXkqb8jblf7/RuasYcSMLneTomZLnbTSqx/ PAoFdPxyQGxsM5UH6bM5HCrVb8I/iGcabuKaLe7TSxNJUd1W0etTgY60Cv9yy/YjHb4F cjkcbJf/5/kqn6uwc0RORJdC9CWzCsByJFbRtEzujJ4jDXpGnZjSK4YkLkc2Mm+3NpM7 BlEA== X-Received: by 10.204.225.204 with SMTP id it12mr4719554bkb.75.1363462481136; Sat, 16 Mar 2013 12:34:41 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.10.144 with HTTP; Sat, 16 Mar 2013 12:33:49 -0700 (PDT) Date: Sat, 16 Mar 2013 20:33:49 +0100 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=485b3970ceeada87c304d80fd81e Subject: [PHP-DEV] __invokeStatic() method From: dnl.rlnd@gmail.com (Daniele Orlando) --485b3970ceeada87c304d80fd81e Content-Type: text/plain; charset=UTF-8 Hi List, I'm interested in proposing an RFC and I would know your opinion. === Current Situation === Since PHP 5.3 we can use an object instance, who defines the __invoke() method, as a callable object. Example: // PHP Code. class Runnable { public function __invoke() { echo "Runned"; } } $r = new Runnable(); $r(); // Output Runned === The Idea === In Python, when you construct an object, you don't need to use the "new" keyword but you just invoke the class name followed by "()", like the class is a function. Example: // Python Code. class A: pass A() // Output. <__main__.A instance at %address> Now, would be interesting to extend the PHP __invoke() method adding an __invokeStatic() method, like happens with __call() and __callStatic() methods. In this way could be possible to use a class name to invoke the __invokeStatic() method. Example: // PHP Code. class TrueRunnable { public static function __invokeStatic() { echo "Runned"; } } TrueRunnable(); // Output. Runned But the possibility are endless: class A { public static function __invokeStatic() { return new A(); } public method m() {} } A()->m(); // or class A { private $_instance; public static function __invokeStatic() { // Singleton pattern. if (self::$_instance) { return self::$_instance; } return self::$_instance = new A(); } public method m() {} } A()->m(); === Conclusion === This feature makes the __invoke() method consistent with the __call() and __callStatic() methods, and opens the door to many cool stuff. Any feedback is appreciated. Daniele Orlando --485b3970ceeada87c304d80fd81e--