Edit report at https://bugs.php.net/bug.php?id=65643&edit=1

 ID:                 65643
 Updated by:         johan...@php.net
 Reported by:        yuri dot sulyma at gmail dot com
 Summary:            Dynamically created methods cannot be called
                     directly
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Class/Object related
 Operating System:   OS X 10.8.4
 PHP Version:        5.5.3
 Block user comment: N
 Private report:     N

 New Comment:

Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

This is a limitation of PHP's type system. Functions/methods and variables 
don't share a common namespace. Currently there is no plan to change this.


Previous Comments:
------------------------------------------------------------------------
[2013-09-09 18:13:07] yuri dot sulyma at gmail dot com

Description:
------------
Methods dynamically created by assigning a closure to a property of $this 
cannot be called directly, but must instead by assigned to a variable first.

Test script:
---------------
class O {
  public $f;

  function __construct() {
    $this->f = function() {
      echo "Dynamic method\n";
    };
  }
}

$o = new O();
$f = $o->f;
$f();
$o->f();


Expected result:
----------------
Dynamic method
Dynamic method

Actual result:
--------------
Dynamic method
Fatal error:  Call to undefined method O::f()


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



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

Reply via email to