I have a PHP class file A with a static variable, I have one class file B that uses that class A and instantiates its static variable. i wish to access Class A's ststic varibale from another class C in another file. How do i do this. I tried this.I know of the singleton structure but am not sure it applies to this. take a look below of what am trying to achieve. Please not i do not wish to use sessions.
classA.php
<?php
Class A{
public static $foo = array ();
public static function doSomething(){
//... Do some process and instantiate static vairable $face
self::$foo = outputofsomeprocess();
}
}
?>
classB.php
<?php
require_once "classA.php";
class B{
public function dosomethingelse(){
A::doSomething();
}
}
?>
classC.php
<?php
require_once "classA.php";
class C{
public function dosomethingelse(){
echo A::$foo[0];
}
}
?>
I get null from the echo in class C
Coming from a C# background, it's a bit different but that should do the trick.
class A1 {
public static $foo = array();
}
<?php
require_once 'classA.php';
class B2 {
public static function doSomethings() {
var_dump(A1::$foo);
}
}
B2::doSomethings();