I am wondering if there is a short notation in PHP for getting an object field when creating an object.
For example, in Java, I do not need to put the newly created object in a variable to get one of the fields. Example:
public class NewClass { public int testNum = 5; }
now, to get the testNum field in the newly created object, all I have to do is:
int num = (new NewClass()).testNum;
Although a similar case in PHP would force me to do this:
$obj = new NewClass(); $num = $obj->testNum;
Is there a way in PHP to do this in one statement? Note. I can not edit classes.
source share