Getting "Fatal error:" when access a class property outside class

Hello guys

Here is my code


class a{


public function __construct()
{
	$this->file = 123;
}



}

echo a::$file;

Error:


Fatal error: Access to undeclared static property: a::$file on line 14

How can I access the “file” property outside the class statictically?

Thanks

Properly declare it:

class a{ 

public static $file;

public function __construct() 
{ 
    self::file = 123; //update this line too
} 



} 

Also, can I ask why you want it to be a static property? It doesn’t look like based on the very simple example, that it would need to be static…

Oh, and Constructors (to my knowledge) are not executed in Static classes, so your mix of static properties with an instantiated class is very odd.

What you may be wanting to achieve:

class a{ 

public $file;

public function __construct() 
{ 
    $this->file = 123; 
} 



} 

$myclassA = new a();
echo $myclassA->file;