php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #51326 Closure must be used as object property
Submitted: 2010-03-18 21:21 UTC Modified: 2010-03-21 19:47 UTC
From: frederic dot hardy at mageekbox dot net Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.3.2 OS: FreeBSD 7.1
Private report: No CVE-ID: None
 [2010-03-18 21:21 UTC] 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

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-03-19 00:58 UTC] felipe@php.net
-Package: *General Issues +Package: Scripting Engine problem
 [2010-03-21 19:47 UTC] johannes@php.net
-Status: Open +Status: Bogus
 [2010-03-21 19:47 UTC] johannes@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 07:01:32 2024 UTC