From:             easteregg at verfriemelt dot org
Operating system: Linux
PHP version:      5.4.16
Package:          Scripting Engine problem
Bug Type:         Bug
Bug description:wrong late static binding in traits

Description:
------------
Hi

when i use a trait with late static bindings i get the wrong bindings, when
i use 
an object A with a trait T and then inherit this trait to a new object B
and call 
the trait T from within that object B, i will get an late binding to object
A 
instead of object B as expected

where as when use the traitmethod within the object A and inherit this for
object 
B and then call it, the static binding are bound to object b as expected

Test script:
---------------
<?php 
    trait getObjectById { 

        public static $_cache = []; 
         
        public static function get($id,$autoload = true) { 
            if (!isset(static::$_cache[$id])) { 
                static::$_cache[$id] = new static($id, $autoload); 
            } 

            return static::$_cache[$id]; 
        } 
    } 
     
    class User { use getObjectById; } 
     
    class User2 extends User { } 
     
    //class User3 extends User { use getObjectById; }
    // var_dump(User3::get(1)) would return the right object cause the
trait is overwritten
     
    var_dump(User::get(1)); 
    var_dump(User2::get(1));

Expected result:
----------------
object(User)[1]
object(User2)[1]

Actual result:
--------------
object(User)[1]
object(User)[1]

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

Reply via email to