I'm trying to get a static instance of a class in another php class (singleton pattern), but it throws a syntax error "Parse error: syntax error, unexpected '(', waiting ',' or ';'".Can someone explain me why I can not do that in Php?. I am using php 5.5.38.
Example code:
<?php
Class A{
private static $instance=null;
private function __Constrcut(){
#Some initialization of parameters
}
public static function getInstance(){
if(self::$instance==null){
self::$instance=new A();
}
return self::$instance;
}
}
?>
Another class file
<?php
include ('path/to/A class/A.php');
Class B{
#Line error
private static $a_instance = A::getInstance();
public funtion __Construct(){
#Some parameters....
}
#Some other functions....
}
?>
Thank you for helpme :) .
Aucun commentaire:
Enregistrer un commentaire