Kod
abstract class Expression {
private static $keycount=0;
private $key;
abstract function interpret( Context $context );
function getKey() {
if ( ! isset( $this->key ) ) {
self::$keycount++;
$this->key=self::$keycount;
}
return $this->key;
}
}
class LiteralExpression extends Expression {
private $value;
function __construct( $value ) {
$this->value = $value;
}
function interpret( Context $context ) {
$context->replace($this, $this->value );
}
}
$context = new Context();
$literal = new LiteralExpression( 'four');
$literal->interpret( $context );
private static $keycount=0;
private $key;
abstract function interpret( Context $context );
function getKey() {
if ( ! isset( $this->key ) ) {
self::$keycount++;
$this->key=self::$keycount;
}
return $this->key;
}
}
class LiteralExpression extends Expression {
private $value;
function __construct( $value ) {
$this->value = $value;
}
function interpret( Context $context ) {
$context->replace($this, $this->value );
}
}
$context = new Context();
$literal = new LiteralExpression( 'four');
$literal->interpret( $context );
Nie rozumiem parametru $this funkcji replace() w LiberalExpression::interpret. Co dokładnie dostaje w pierwszym parametrze funkcja replace(). Pierwszy raz spotykam się ze zmienną $this bez odwołania do konkretnej zmiennej.