kahlan\Scope::__get PHP Метод

__get() публичный Метод

Getter.
public __get ( string $key ) : mixed
$key string The name of the variable.
Результат mixed The value of the variable.
    public function &__get($key)
    {
        if (array_key_exists($key, $this->_data)) {
            return $this->_data[$key];
        }
        if (array_key_exists($key, $this->_given)) {
            $scope = static::current();
            $scope->{$key} = $this->_given[$key]($scope);
            return $scope->__get($key);
        }
        if ($this->_parent !== null) {
            return $this->_parent->__get($key);
        }
        if (in_array($key, static::$blacklist)) {
            if ($key === 'expect') {
                throw new Exception("You can't use expect() inside of describe()");
            }
        }
        throw new Exception("Undefined variable `{$key}`.");
    }

Usage Example

Пример #1
0
 /**
  * Getter.
  *
  * @param  string $key The name of the variable.
  * @return mixed  The value of the variable.
  */
 public function &__get($key)
 {
     if (array_key_exists($key, $this->_data)) {
         return $this->_data[$key];
     }
     if (array_key_exists($key, $this->_given)) {
         $scope = static::current();
         $scope->{$key} = $this->_given[$key]($scope);
         return $scope->__get($key);
     }
     if ($this->_parent !== null) {
         return $this->_parent->__get($key);
     }
     if (in_array($key, static::$blacklist)) {
         if ($key === 'expect') {
             throw new Exception("You can't use expect() inside of describe()");
         }
     }
     throw new Exception("Undefined variable `{$key}`.");
 }