php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26802 Can't call function through static property
Submitted: 2004-01-05 17:03 UTC Modified: 2004-02-11 05:43 UTC
From: adam at trachtenberg dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS OS: *
Private report: No CVE-ID: None
 [2004-01-05 17:03 UTC] adam at trachtenberg dot com
Description:
------------
You cannot dynamically call a static methods using a 
variable. This works for regular functions, for example:

function foo() {}
$f = 'foo';
$f();

Reproduce code:
---------------
class foo {
	static public function bar() {
		print "baz\n";
	}
}

foo::bar();
$static_method = "foo::bar";
$static_method();

Expected result:
----------------
baz
baz

Actual result:
--------------
PHP Fatal error:  Call to undefined function foo::bar() 
in /php/test.php on line 10
baz

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-05 19:49 UTC] helly@php.net
Updated test to all different versions showed that indeed one way of calling a class is wrong.

class::$prop() should evaluate class::$prop and call that function. But instead it calls the method specified by the result in the class given. In other words the class name is used twice.
 [2004-02-11 05:43 UTC] zeev@php.net
This bug has been fixed in CVS.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.

$static_method = "foo::bar";
$static_method();

is not supposed to work.  The incompatibility with PHP 4 has been fixed.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Aug 19 22:01:27 2024 UTC