Bug #69933 [Fbk->Opn]: Reflection API no longer allows to override static properties

From: Date: Fri, 26 Jun 2015 18:41:57 +0000
Subject: Bug #69933 [Fbk->Opn]: Reflection API no longer allows to override static properties
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-193923@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69933&edit=1

 ID:                 69933
 User updated by:    maf dot michal at gmail dot com
 Reported by:        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
 Type:               Bug
-Package:            Class/Object related
+Package:            Reflection related
 Operating System:   unix
 PHP Version:        7.0Git-2015-06-25 (snap)
 Block user comment: N
 Private report:     N

 New Comment:

<?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);
?>


Previous Comments:
------------------------------------------------------------------------
[2015-06-25 22:08:46] 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-25 20:17:17] 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


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69933&edit=1


Thread (8 messages)

« previous php.bugs (#193923) next »