Bug #62547 [Opn->Ver]: callback of private function in parent class works but static vars are lost

From: Date: Fri, 28 Aug 2015 11:50:53 +0000
Subject: Bug #62547 [Opn->Ver]: callback of private function in parent class works but static vars are lost
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-195591@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62547&edit=1 ID: 62547 Updated by: nikic@php.net Reported by: beat at joomlapolis dot com Summary: callback of private function in parent class works but static vars are lost -Status: Open +Status: Verified Type: Bug Package: Class/Object related Operating System: osX 10.6.8 PHP Version: 5.3.14 Block user comment: N Private report: N New Comment: Still present: https://3v4l.org/cXfUJ HHVM does this right. Previous Comments: ------------------------------------------------------------------------ [2012-07-13 12:01:54] beat at joomlapolis dot com Description: ------------ In the case below where the callback function is private, its static local variable is lost during call of inherited class, t if the callback function is private as below, it still gets called, but the local static variable is null instead of initialized like in PHP 5.2, where it works. Also if you make the callback function "protected" instead of "private", the result is correct, as expected. This is reproducible at least on PHP 5.3.8. Test script: --------------- class ok { public function t() { $this->replacer( '*' ); return preg_replace_callback( '/(t)/', array( $this, 'replacer'), 'this is a simple test' ); } private function replacer( $input ) { static $cache = '-'; if ( ! is_array( $input ) ) { $cache = $input; } else { return $cache . $input[1] . $cache; } } } class buggyphp extends ok {} class buggyphptoo extends ok { public function t() { return parent::t(); } } $buggy = new buggyphp(); echo 'Result buggyphp: ' . $buggy->t(); echo "\n"; $buggy = new buggyphptoo(); echo 'Result buggyphptoo: ' . $buggy->t(); echo "\n"; $a = new ok(); echo 'Result ok: ' . $a->t(); exit(); Expected result: ---------------- Result buggyphp: *t*his is a simple *t*es*t* Result buggyphptoo: *t*his is a simple *t*es*t* Result ok: *t*his is a simple *t*es*t* Actual result: -------------- Result buggyphp: -t-his is a simple -t-es-t- Result buggyphptoo: -t-his is a simple -t-es-t- Result ok: *t*his is a simple *t*es*t* ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62547&edit=1

« previous php.bugs (#195591) next »