Sign in to follow this  

[web] [PHP] Tell a variable's class?

This topic is 3578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have an unknown variable and I want to figure out what type it is. For the built-in types I can just use the is_bla() functions; but how do I test if the variable is of a cutsom class I implmeneted? gettype() returns only an object, so it won't do. The only way I can think of is calling serialize() and then scanning the string for the object's class name, but that wouldn't be very efficient. Thanks.

Share this post


Link to post
Share on other sites
You can either use
$classname = get_class($object);
-> http://www.php.net/manual/en/function.get-class.php
to get the name of the class, or if you want to know if an object is an instance of a certain class
($object instanceof SomeClass)
-> http://www.php.net/manual/en/language.operators.type.php

Share this post


Link to post
Share on other sites

This topic is 3578 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this