Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix #77291: magic methods inherited from a trait may be ignored
When adding methods from a trait, we must not assume that a method name with the same length as the name of the using class is either a PHP 4 style constructor, or not a magic method at all – it may well be another magic method. We mostly preserve the spirit of the optimization which caused this regression, and avoid string comparisons for all method names which can never be magic methods.
- Loading branch information
Showing
3 changed files
with
56 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--TEST-- | ||
Bug #77291 (magic methods inherited from a trait may be ignored) | ||
--FILE-- | ||
<?php | ||
|
||
trait AccessibleProperties | ||
{ | ||
public function __isset($property) | ||
{ | ||
return property_exists($this, $property); | ||
} | ||
|
||
public function __get($property) | ||
{ | ||
if (property_exists($this, $property)) { | ||
return $this->$property; | ||
} | ||
} | ||
} | ||
|
||
class Foo4567 { | ||
use AccessibleProperties; | ||
|
||
protected $a = 'Some value'; | ||
} | ||
|
||
class Foo45 { | ||
use AccessibleProperties; | ||
|
||
protected $a = 'Some value'; | ||
} | ||
|
||
$foo = new Foo4567; | ||
var_dump(isset($foo->a)); | ||
$foo = new Foo45; | ||
var_dump($foo->a); | ||
?> | ||
===DONE=== | ||
--EXPECT-- | ||
bool(true) | ||
string(10) "Some value" | ||
===DONE=== |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters