php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #65643 Dynamically created methods cannot be called directly
Submitted: 2013-09-09 18:13 UTC Modified: 2013-09-09 18:57 UTC
From: yuri dot sulyma at gmail dot com Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.5.3 OS: OS X 10.8.4
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yuri dot sulyma at gmail dot com
New email:
PHP Version: OS:

 

 [2013-09-09 18:13 UTC] 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()

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2013-09-09 18:57 UTC] johannes@php.net
-Status: Open +Status: Not a bug
 [2013-09-09 18:57 UTC] johannes@php.net
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.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 01:01:35 2024 UTC