Bug #74269 [NEW]: It's possible to override trait property with different value

From: Date: Sat, 18 Mar 2017 20:58:32 +0000
Subject: Bug #74269 [NEW]: It's possible to override trait property with different value
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-207924@lists.php.net to get a copy of this message
From:             bugsphp077 at nabialek dot org
Operating system: Windows
PHP version:      7.0.17
Package:          Class/Object related
Bug Type:         Bug
Bug description:It's possible to override trait property with different value

Description:
------------
According to PHP manual:

"If a trait defines a property then a class can not define a property
with the same name unless it is compatible (same visibility and initial
value), otherwise a fatal error is issued. Before PHP 7.0.0, defining a
property in the class with the same visibility and initial value as in
the trait, raised an E_STRICT notice. "

but it seems it's not completely true. Some casts are done, so in fact
you can use different value.

Test script:
---------------
trait PropertiesTrait
{
    public $same = true;

    public function message()
    {
        if ($this->same === true) {
            return "A";
        }
        return "B";
    }
}

class PropertiesExample
{
    use PropertiesTrait;
    public $same = 2;
}

$example = new PropertiesExample();
echo $example->message();

Expected result:
----------------
Fatal error as described in documentation.

Actual result:
--------------
B (Same result is for PHP 7.1.1). No warning/notice is generated

-- 
Edit bug report at https://bugs.php.net/bug.php?id=74269&edit=1
-- 
Try a snapshot (PHP 5.4):   https://bugs.php.net/fix.php?id=74269&r=trysnapshot54
Try a snapshot (PHP 5.5):   https://bugs.php.net/fix.php?id=74269&r=trysnapshot55
Try a snapshot (trunk):     https://bugs.php.net/fix.php?id=74269&r=trysnapshottrunk
Fixed in SVN:               https://bugs.php.net/fix.php?id=74269&r=fixed
Fixed in release:           https://bugs.php.net/fix.php?id=74269&r=alreadyfixed
Need backtrace:             https://bugs.php.net/fix.php?id=74269&r=needtrace
Need Reproduce Script:      https://bugs.php.net/fix.php?id=74269&r=needscript
Try newer version:          https://bugs.php.net/fix.php?id=74269&r=oldversion
Not developer issue:        https://bugs.php.net/fix.php?id=74269&r=support
Expected behavior:          https://bugs.php.net/fix.php?id=74269&r=notwrong
Not enough info:            https://bugs.php.net/fix.php?id=74269&r=notenoughinfo
Submitted twice:            https://bugs.php.net/fix.php?id=74269&r=submittedtwice
register_globals:           https://bugs.php.net/fix.php?id=74269&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=74269&r=php4
Daylight Savings:           https://bugs.php.net/fix.php?id=74269&r=dst
IIS Stability:              https://bugs.php.net/fix.php?id=74269&r=isapi
Install GNU Sed:            https://bugs.php.net/fix.php?id=74269&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=74269&r=float
No Zend Extensions:         https://bugs.php.net/fix.php?id=74269&r=nozend
MySQL Configuration Error:  https://bugs.php.net/fix.php?id=74269&r=mysqlcfg



Thread (4 messages)

« previous php.bugs (#207924) next »