php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #69933 Reflection API no longer allows to override static properties
Submitted: 2015-06-25 20:17 UTC Modified: 2016-03-28 07:32 UTC
From: maf dot michal at gmail dot com Assigned: krakjoe (profile)
Status: Closed Package: Reflection related
PHP Version: 7.0Git-2015-06-25 (snap) OS: unix
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: maf dot michal at gmail dot com
New email:
PHP Version: OS:

 

 [2015-06-25 20:17 UTC] maf dot michal at gmail dot com
Description:
------------
As I was running tests of one of my PHP libs using travis-ci I encountered some issue with late static binding.

It seems to be not possible to override static property and access proper values with static:: keyword

https://travis-ci.org/majkel89/tcpdf-warper/jobs/68057687

On the other hand the problem might be with reflection API that cannot override static properties any more.

Non the less I provided full source code as long with tests scripts and results sets.

PS: Would it be wiser to replace static property storing default arguments with inline array in getArguments both for performance and memory improvements ? This way the problem would be fixed.

Test script:
---------------
https://github.com/majkel89/tcpdf-warper/blob/master/tests/org/majkel/tcpdfwarper/AbstractOpTest.php#L141

Expected result:
----------------
https://travis-ci.org/majkel89/tcpdf-warper/jobs/68057674

Actual result:
--------------
https://travis-ci.org/majkel89/tcpdf-warper/jobs/68057687

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-06-25 22:08 UTC] requinix@php.net
-Status: Open +Status: Feedback
 [2015-06-25 22:08 UTC] requinix@php.net
Thank you for this bug report. To properly diagnose the problem, we
need a short but complete example script to be able to reproduce
this bug ourselves. 

A proper reproducing script starts with <?php and ends with ?>,
is max. 10-20 lines long and does not require any external 
resources such as databases, etc. If the script requires a 
database to demonstrate the issue, please make sure it creates 
all necessary tables, stored procedures etc.

Please avoid embedding huge scripts into the report.

How about a repro that doesn't rely on your test framework?
 [2015-06-26 18:41 UTC] maf dot michal at gmail dot com
-Summary: Late-static binding seems not working for static properties +Summary: Reflection API no longer allows to override static properties -Status: Feedback +Status: Open -Package: Class/Object related +Package: Reflection related
 [2015-06-26 18:41 UTC] maf dot michal at gmail dot com
<?php
class Base {
    protected static $prop = 'BASE';
    public function getProp() {
        return static::$prop;
    }
}
class Mock extends Base { }

$obj = new Mock;
$excepted = 'REFLECTED';

$property = new ReflectionProperty('Base', 'prop');
$property->setAccessible(true);
$property->setValue($excepted);

$actual = $obj->getProp();
echo "Schould be `{$excepted}` and is `{$actual}`\n";
// exit($actual !== $excepted ? 1 : 0);
?>
 [2015-06-26 18:47 UTC] maf dot michal at gmail dot com
proof: https://travis-ci.org/majkel89/php7-bug
 [2015-08-23 15:42 UTC] j dot tvr at centrum dot cz
https://3v4l.org/nvhZQ
 [2015-09-19 20:08 UTC] j dot tvr at centrum dot cz
I spent some time playing with this bug and it turned out to be worse problem that it originally seemed. Changing value of static property with reflection **permanently breaks the inheritance chain**.

https://3v4l.org/T43Sh
 [2015-10-12 20:09 UTC] j dot tvr at centrum dot cz
Could someone look into this?
 [2016-03-28 07:32 UTC] krakjoe@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: krakjoe
 [2016-03-28 07:32 UTC] krakjoe@php.net
This was fixed in 7.0.1, someone forgot to update the bug.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Dec 19 04:01:28 2024 UTC