php manual code reuse learning class trait

After Trait defines an attribute class can not define the attributes of the same name, or will cause fatal error. Kind of exceptions: is compatible attribute (the same access visibility, initial default values). Prior to PHP 7.0, the properties are compatible, then there will be E_STRICT reminder.

{PropertiesTrait trait
    public = $ Same, to true;
    public $ Different = false;
}

class PropertiesExample {
    use PropertiesTrait;
    public $ = Same, to true; // After PHP 7.0.0 No problem, the previous version is E_STRICT remind
    public $ different = true; / / fatal error
}
?>

Guess you like

Origin www.cnblogs.com/gaogaoxingxing/p/11128405.html