jeudi 27 septembre 2018

Static Variable Not overriding

Class with static variable which is not overriding its value.

My code is

class Export {

protected static $title = '';

public function __construct($title) {
   self::$title = $title;

}

// This event function will trigger every time new instance is created.
public static function event($args)
{
   echo self::$title; // This prints only last assigned value "title2"
}

}

How i called is

$a = new Export('title1'); //in the event function it has to echo "title1" but it is echoing "title2"
$b = new Export('title2');

I cant able to get title1 value in the "event()" method inside the class. anyone help on this.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire