No static method callbacks anmore?

php.internals

Jan Schneider

22 years ago
Hi, before reporting a bug, I want to make sure that this is no intentional change. Are static methods no longer supported as callbacks? preg_replace_callback('/some pattern/', array('MyClass', 'Method'), $subject) raises a warning atm: Unable to call custom replacement function in ... Jan.
-- http://www.horde.org - The Horde Project http://www.ammma.de - Neue Wege des Lernens http://www.tip4all.de - Deine private Tippgemeinschaft

Hans Lellelid

22 years ago
I was just about to post the same bug ... Except that I couldn't quite build a reproducing testcase. I get exactly the same message in my code, but when I created a small static class to reproduce the problem it seems to work fine ... (static or non-static or mixture) Hans Jan Schneider wrote:

Andi Gutmans

22 years ago
Can you do a reverse apply of the following diff and let me know if it fixes the problem? http://cvs.php.net/diff.php/ZendEngine2/zend_execute_API.c?r1=1.274&r2=1.275&ty=u Thanks, Andi At 05:04 PM 3/15/2004 +0100, Jan Schneider wrote:

Jan Schneider

22 years ago
Zitat von Andi Gutmans <andi@zend.com>:
> Can you do a reverse apply of the following diff and let me know if it > fixes the problem? > http://cvs.php.net/diff.php/ZendEngine2/zend_execute_API.c?r1=1.274&r2=1.275&ty=u
No, it doesn't.
> At 05:04 PM 3/15/2004 +0100, Jan Schneider wrote: >> Hi, >> >> before reporting a bug, I want to make sure that this is no intentional >> change. Are static methods no longer supported as callbacks? >> >> preg_replace_callback('/some pattern/', array('MyClass', 'Method'), >> $subject) >> >> raises a warning atm: >> Unable to call custom replacement function in ...
Jan.
-- http://www.horde.org - The Horde Project http://www.ammma.de - Neue Wege des Lernens http://www.tip4all.de - Deine private Tippgemeinschaft

Hans Lellelid

22 years ago
Here's a script to reproduce the problem w/ static callbacks. The problem only seems to happen when the function calling the static function using preg_replace_callback() is not declared 'static' itself, but is accessed as a static function. Also, this only happens when being called from another non-static method. (let me know if you'd rather I post this as a bug) <?php class RegexpCallback { private static $vars = array('one' => 1, 'two' => 2); function replace($value) { $sb = preg_replace_callback('/\$\{([^}]+)\}/', array('RegexpCallback', 'callback'), $value); return $sb; } private static function callback($matches) { $propertyName = $matches[1]; return self::$vars[$propertyName]; } } class Test { function __construct() { $value = 'one = ${one}, two=${two}'; $return1 = RegexpCallback::replace($value); echo $return1 . "\n"; } } $t = new Test(); ?> --- Expected --- one = 1, two = 2 --- Actual Results -- Warning - preg_replace_callback(): Unable to call custom replacement function one = ${one}, two = ${two} It works when .... (1) called directly instead of in Test constructor, (2) the replace() method is declared 'static', (3) instantiate RegexpCallback and call ->replace() method on the instance rather than as a static method. I actually have an interest in having the replace() method in my example be either static or not... which is why I'm not entirely satisfied with the fact that making it static fixes the problem. Hans

Andi Gutmans

22 years ago
No need to post it as a bug. I'll look into it. Thanks. At 11:51 AM 3/15/2004 -0500, Hans Lellelid wrote:

Andi Gutmans

22 years ago
Should be fixed now. Thanks for the reproducing test case. At 11:51 AM 3/15/2004 -0500, Hans Lellelid wrote:

Jan Schneider

22 years ago
Zitat von Andi Gutmans <andi@zend.com>:
> Should be fixed now. Thanks for the reproducing test case.
Yeah, works fine now, thanks. Jan.
-- http://www.horde.org - The Horde Project http://www.ammma.de - Neue Wege des Lernens http://www.tip4all.de - Deine private Tippgemeinschaft