If I have:
<?php
class SomeClass extends SomeOtherClass{
private $access_code = 'TX9999';
private static function SomeMethod(){
}
}
?>
And do
<?
self::SomeMethod();
?>
how do I correctly access $access_code in ::SomeMethod()
More Info
What Im actually facing is more complex.
I have a class with methods that are and must remain static.
I know how to call other methods using self.
However across the class I have things that would ordinarily make sense as constants and variables.
I realise that I haven’t got an instance in the normal way and am looking for away to share variables between some of the static methods of the class, some are volatile, some fixed
This would do what you want; it creates an instance of itself first before being able to access the private instance variable
$access_code.If you want a class variable instead of instance variable, you have to declare the
$access_codelike this:Then call it from the static method like this:
Btw, you can’t call
::SomeMethod()from outside the class. In order to do that, you need to make itpublic: