Skip to content

Instantly share code, notes, and snippets.

@rgantt
Created August 31, 2011 15:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgantt/1183844 to your computer and use it in GitHub Desktop.
Save rgantt/1183844 to your computer and use it in GitHub Desktop.
PHP 5.4.0alpha3 traits abuse
<?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()
<?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