Re: reproduce script (Re: [PHP-DEV] No static method callbacks anmore?)
| From: | Andi Gutmans | Date: | Mon, 15 Mar 2004 16:56:51 +0000 |
| Subject: | Re: reproduce script (Re: [PHP-DEV] No static method callbacks anmore?) | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-8532@lists.php.net to get a copy of this message | ||
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:
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