I've done some research and found this SO-Post and this Php Docs...
Now my problem is, it's not working!
My current php version is 5.4.12
which this feature that I'm after is compatible with 5.4
. I'm wondering why it's not working?
This is what I'm after and the stuff I've tried so far...
For example, we have a class of:
class MyClass
{
private $var = "";
public function __construct()
{
// either with or without
// return $this;
}
public static function newObj()
{
return new self;
}
public function setVar($var)
{
$this->var = $var;
}
}
And I've tried these:
$obj = (new MyClass)->setVar("foo");
// or
$obj = MyClass::newObj()->setVar("foo");
But none work and when I get the $obj
value using var_dump
, it's just null
.
EDIT
I've also tried and placed an echo
inside the __construct
to see if the class is being initialize, and it is.