Bug #62547 [Ver->Csd]: callback of private function in parent class works but static vars are lost
| From: | cmb@php.net | Date: | Wed, 07 Oct 2020 12:54:14 +0000 |
| Subject: | Bug #62547 [Ver->Csd]: 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-229447@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: cmb@php.net
Reported by: beat at joomlapolis dot com
Summary: callback of private function in parent class works
but static vars are lost
-Status: Verified
+Status: Closed
Type: Bug
Package: Class/Object related
Operating System: osX 10.6.8
PHP Version: 5.3.14
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
Fixed as of PHP 7.4.0.
Previous Comments:
------------------------------------------------------------------------
[2015-08-28 11:50:50] nikic@php.net
Still present: https://3v4l.org/cXfUJ HHVM does this right.
------------------------------------------------------------------------
[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