PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
error_reporting(E_ALL | E_STRICT);
class A
{
var $a = 10;
function nonstaticmethod()
{
echo "a = $this->a ";
}
static function staticmethod()
{
echo "a = $a";
}
}
$a = new A;
$a->nonstaticmethod();
A::staticmethod();
?>
how I can access variable $a inside function staticmethod( )?
In C++, static gives you a slight performance benefit, because with it you promise not to access any of the instance's member variables. In PHP, the syntax for static and regular is different, so really if you're going to call the method like $a->, it should not be static.