0

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

classA.php

<?php
Class A{
   public static $foo = array ();

   public static function doSomething(){
       //... Do some process and instantiate static vairable $face
       $face = outputofsomeprocess();
   }
}
?>
classB.php
<?php
require_once "classA.php";
class B{
    public function dosomethingelse(){
        classA::doSomething();
    }
}
?>

classC.php
<?php
require_once "classA.php";
class C{
    public function dosomethingelse(){
       echo classA::$foo[0];
    }
}
?>

How do I do this correctly, because in classC classA::$foo[0] return null.

2
Contributors
1
Reply
10
Views
2 Years
Discussion Span
Last Post by pritaeas
0
echo A::$foo[0];

The class name is A, not classA. Besides that, I dont see foo getting a value anywhere, it is an empty array.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.