[PHP-DEV] reproduce script (Re: [PHP-DEV] No static method callbacks anmore?)
by Hans Lellelid other posts by this author
Mar 15 2004 4:51PM messages near this date
Re: [PHP-DEV] No static method callbacks anmore?
|
[PHP-DEV] Re: reproduce script (Re: [PHP-DEV] No static method callbacks
anmore?)
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
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php
Thread:
Jan Schneider
Andi Gutmans
Jan Schneider
Hans Lellelid
Andi Gutmans
Jan Schneider
Andi Gutmans
Hans Lellelid
|