Bug #51326 [Opn->Bgs]: Closure must be used as object property

From: Date: Sun, 21 Mar 2010 18:47:01 +0000
Subject: Bug #51326 [Opn->Bgs]: Closure must be used as object property
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-148809@lists.php.net to get a copy of this message
Edit report at http://bugs.php.net/bug.php?id=51326&edit=1

 ID:               51326
 Updated by:       johannes@php.net
 Reported by:      frederic dot hardy at mageekbox dot net
 Summary:          Closure must be used as object property
-Status:           Open
+Status:           Bogus
 Type:             Bug
 Package:          Scripting Engine problem
 Operating System: FreeBSD 7.1
 PHP Version:      5.3.2

 New Comment:

The whole "object handling" of closures was held back in order to get
5.3out. The next major version of PHP (5.4 / 6.0) will most likely add
better oo support. During the discussions this aspect will be
discussed,no need for an additional bug report.


Previous Comments:
------------------------------------------------------------------------
[2010-03-18 21:21:07] frederic dot hardy at mageekbox dot net

Description:
------------
If a class instance has a closure as property, PHP must call
$this->closure->__invoke() instead of say that method class::closure()
does not exist.

Test script:
---------------
<?php

class foo
{
   protected $closure = null;

   function __construct(\closure $closure)
   {
      $this->closure = $closure;
   }

   function callClosure()
   {
      return $this->closure('Closure::__invoke() was called');
   }
}

$foo = new foo(function($string) { echo $string; });

$foo->callClosure();

?>

Expected result:
----------------
Closure::__invoke() was called

Actual result:
--------------
Call to undefined method foo::closure() in /path/to/script.php on line
14


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=51326&edit=1


Thread (2 messages)

« previous php.bugs (#148809) next »