get type in php return "object" and not the object type
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()
).
You can use get_class($object);
http://www.php.net/get_class
To help with your new situation (if I've understood properly)
<?php
namespace Ridiculous\Test\Whatever;
class example {}
$example = new example();
echo get_class($example) . '<br>';
echo basename(get_class($example)); // this may be what you're after
gettype($obj);// Output: "object"
$obj instanceof Myclass;// Output: true (if it's an instance of that class)
gettype()
returns the type of variable, like "string", "integer", "array", etc.
instanceof
checks whether object is instance of that specified class.