php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #20204 $var_classname::function(); returns a parse error. You need to use eval().
Submitted: 2002-10-31 15:34 UTC Modified: 2003-01-28 15:07 UTC
Votes:1
Avg. Score:2.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: nih at phlux dot co dot uk Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4.2.3 OS: Linux
Private report: No CVE-ID: None
 [2002-10-31 15:34 UTC] nih at phlux dot co dot uk
Using

$var_classname:function();

throws up a parse error. This was probably not a feature intended to be included rather than a bug. Currently I have a workaround using this:

print eval("return ".$var_classname."::function();");

Would like to see it implemented in a future version if possible :)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-10-31 15:37 UTC] nih at phlux dot co dot uk
The comma `:' in the first line of code is supposed to be a double comma `::'
 [2003-01-28 15:07 UTC] pollita@php.net
As you state, this calling convention is not supported.  The reason relates to how the Zend engine parses PHP syntax and will not change in the forseeable future.  However, there is cleaner way to accomplish what you're attempting without using eval().

Try:

  return call_user_func(array($varclassname,'function'));

I notice that the documentation for call_user_func fails to note the ability to call static class methods in this way(changing category to documentation problem) and have added an additional paragraph and explanation explaining this.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 12 11:01:35 2024 UTC