im trying to get the type of the object that i receive in the constructor using gettype($this->object)
.
but im only getting "object" my constructor: p
public function __construct($object=null)
{
$this->object=$object;
}
the object that i send to class:
$campaign = new Campaign();
$type = new Nodes\CampaignDatabaseNode($campaign);
$type->checkType();
the checkType(); only echo the type of the object
The is_object() function checks whether a variable is an object. This function returns true (1) if the variable is an object, otherwise it returns false/nothing.
The stdClass is the empty class in PHP which is used to cast other types to object. It is similar to Java or Python object. The stdClass is not the base class of the objects. If an object is converted to object, it is not modified.
The gettype() function returns the type of a variable.
The gettype() function is an inbuilt function in PHP which is used to get the type of a variable. It is used to check the type of existing variable. Syntax: string gettype ( $var ) Parameter: This function accepts a single parameter $var.
Just to explain why gettype() doesn't work as expected since others have already provided the correct answer. gettype()
returns the type of variable — i.e. boolean, integer, double, string, array, object, resource, NULL or unknown type (cf. the gettype()
manual link above).
In your case the variable $campaign
is an object (as returned by gettype()
), and that object is an instance of the class Campaign (as returned by get_class()
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With