Jump to content
  • Advertisement
Sign in to follow this  
Koobazaur

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

This topic is 3794 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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!