My problem may seem simple, but I haven't found a reason why the netbeans code editor throws me a syntax error.
My code:
class bot extends Valores{
private $estado;
function __construct(){
$this->estado = bot::Valores::$mi_estado;
print '$estado=' . $this->estado;
}
}
This small piece of code should be able to get the variable statica
$mi_estado
and save it over the $estado
current class variable.
My other class:
class Valores
{
public static $mi_estado = 0;
public function setEstado($estado) {
self::$mi_estado=estado;
}
public function getEstado() {
return self::$mi_static;
}
}
Thank you and I look forward to your prompt support.
Your code should look like this:
Resulting:
Observations
bot::Valores::$mi_estado;
as the class already extends fromValores
.bot
to display the access to that property, in the constructor method you must match the property with the name of the class and the access to the property in question, like so:Valores::$mi_estado;
Do this:
It is incorrect because you are stating that the class
bot
is trying to accessValores
as if the class is static when it clearly is not.Doing the above results in an error that says:
Since the syntax is:
If you're trying to access a static value outside the scope of the class, then it should be like this:
If in this case you
bot
already inherit fromValores
, you can already access its method and properties; try the following:Resulting:
References.