'Using myProperty is deprecated and will not be possible anymore in TYPO3 v10.0. Use getMyProperty() instead.' * ]; * * /** * * This is my property. * * * * @var bool * * @deprecated (if deprecated) * * @internal (if switched to private) * / * protected $myProperty = true; * } */ /** * This trait has no public properties by default, ensure to add a $deprecatedPublicProperties to your class * when using this trait. */ trait PublicPropertyDeprecationTrait { /** * Checks if the property of the given name is set. * * Unmarked protected properties must return false as usual. * Marked properties are evaluated by isset(). * * This method is not called for public properties. * * @property array $deprecatedPublicProperties List of deprecated public properties * @param string $propertyName * @return bool */ public function __isset(string $propertyName) { if (isset($this->deprecatedPublicProperties[$propertyName])) { trigger_error($this->deprecatedPublicProperties[$propertyName], E_USER_DEPRECATED); return isset($this->$propertyName); } return false; } /** * Gets the value of the property of the given name if tagged. * * The evaluation is done in the assumption that this method is never * reached for a public property. * * @property array $deprecatedPublicProperties List of deprecated public properties * @param string $propertyName * @return mixed */ public function __get(string $propertyName) { if (isset($this->deprecatedPublicProperties[$propertyName])) { trigger_error($this->deprecatedPublicProperties[$propertyName], E_USER_DEPRECATED); } return property_exists($this, $propertyName) ? $this->$propertyName : null; } /** * Sets the property of the given name if tagged. * * Additionally it's allowed to set unknown properties. * * The evaluation is done in the assumption that this method is never * reached for a public property. * * @property array $deprecatedPublicProperties List of deprecated public properties * @param string $propertyName * @param mixed $propertyValue */ public function __set(string $propertyName, $propertyValue) { // It's allowed to set an unknown property as public, the check is thus necessary if (property_exists($this, $propertyName) && isset($this->deprecatedPublicProperties[$propertyName])) { trigger_error($this->deprecatedPublicProperties[$propertyName], E_USER_DEPRECATED); } $this->$propertyName = $propertyValue; } /** * Unsets the property of the given name if tagged. * * @property array $deprecatedPublicProperties List of deprecated public properties */ public function __unset(string $propertyName) { if (isset($this->deprecatedPublicProperties[$propertyName])) { trigger_error($this->deprecatedPublicProperties[$propertyName], E_USER_DEPRECATED); } unset($this->$propertyName); } }