Skip to content

Instantly share code, notes, and snippets.

@everzet
Created May 21, 2012 19:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save everzet/2764223 to your computer and use it in GitHub Desktop.
Save everzet/2764223 to your computer and use it in GitHub Desktop.
<?php
trait one {
public $prop;
protected function someMethod()
{
// do something hidden from the
// outside world
}
}
class two {
use one;
public $prop; // "E_STRICT: This might be incompatible..."
public function someMethod() // But this is completely OK
{
// do something publicly
}
}
// WHY ?
<?php
error_reporting(0);
trait one
{
/** prop1 */
protected $prop = 0;
/** method1 */
public function method() {}
}
class two
{
use one;
/** prop2 */
protected $prop = 0;
/** method2 */
public function method() {}
}
$two = new two();
$refl = new \ReflectionObject($two);
echo $refl->getProperty('prop')->getDocComment() . "\n";
echo $refl->getMethod('method')->getDocComment() . "\n";
#
# Will output:
#
# /** prop1 */
# /** method2 */
#
// WHY ?
@everzet
Copy link
Author

everzet commented May 22, 2012

@marijn again, i'm not talking about overriding default values or access level, i'm talking about inconsistency like that:

<?php

error_reporting(0);

trait one
{
    /** prop1 */
    protected $prop = 0;

    /** method1 */
    public function method() {}
}

class two
{
    use one;

    /** prop2 */
    protected $prop = 0;

    /** method2 */
    public function method() {}
}

$two = new two();
$refl = new \ReflectionObject($two);

echo $refl->getProperty('prop')->getDocComment() . "\n";
echo $refl->getMethod('method')->getDocComment() . "\n";

will output:

/** prop1 */
/** method2 */

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment