|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2013-06-14 15:15 UTC] laruence@php.net
-Status: Open
+Status: Not a bug
[2013-06-14 15:15 UTC] laruence@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Nov 27 05:00:01 2025 UTC |
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]