Created
August 31, 2011 15:35
-
-
Save rgantt/1183844 to your computer and use it in GitHub Desktop.
PHP 5.4.0alpha3 traits abuse
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
<?php | |
/** | |
* ============ | |
* Defect: can alias-override class constructor, but only when using legacy constructor naming convention | |
* ============ | |
*/ | |
trait SomeTrait { | |
private function constructor() { | |
echo "this is abuse\n"; | |
} | |
} | |
class SomeClass { | |
use SomeTrait { | |
constructor as __construct; | |
} | |
public function SomeClass() { | |
echo "this is a constructor"; | |
} | |
} | |
$c = new SomeClass(); // Fatal error: Call to private SomeClass::__construct() |
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
<?php | |
/** | |
* ============ | |
* Defect: can override class constructor, but only when using legacy constructor naming convention | |
* ============ | |
*/ | |
trait SomeTrait { | |
private function __construct() { | |
echo "this is abuse\n"; | |
} | |
} | |
class SomeClass { | |
use SomeTrait; | |
public function SomeClass() { | |
echo "this is a constructor"; | |
} | |
} | |
$c = new SomeClass(); // Fatal error: Call to private SomeClass::__construct() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment