BetterReflection\Reflection\ReflectionClass::removeProperty PHP Method

removeProperty() public method

Remove a property from the class.
public removeProperty ( string $propertyName ) : boolean
$propertyName string
return boolean
    public function removeProperty($propertyName)
    {
        $lowerName = strtolower($propertyName);
        foreach ($this->node->stmts as $key => $stmt) {
            if ($stmt instanceof PropertyNode) {
                $propertyNames = array_map(function (Node\Stmt\PropertyProperty $propertyProperty) {
                    return strtolower($propertyProperty->name);
                }, $stmt->props);
                if (in_array($lowerName, $propertyNames, true)) {
                    $this->cachedProperties = null;
                    unset($this->node->stmts[$key]);
                    return true;
                }
            }
        }
        return false;
    }

Usage Example

 /**
  * {@inheritdoc}
  */
 public function removeProperty($methodName)
 {
     return $this->reflectionClass->removeProperty($methodName);
 }