ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> php-Dev
php-Dev
[PHP-DEV] Re: reproduce script (Re: [PHP-DEV] No static method callbacks anmore?)
by Andi Gutmans other posts by this author
Mar 16 2004 2:52PM messages near this date
[PHP-DEV] reproduce script (Re: [PHP-DEV] No static method callbacks anmore?) | [PHP-DEV] Re: reproduce script (Re: [PHP-DEV] No static method callbacks anmore?)
Should be fixed now. Thanks for the reproducing test case.

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

-- 
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

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved