Jump to content

return type of object variable


fruid
 Share

Recommended Posts

how can I return the type of an object?

if it's a page array return PageArray. If it's a single page return PageObject etc.

In plain php, this is done by gettype. When I use that here, everything is object, so it's not useful…

Link to comment
Share on other sites

You're confusing variable type and object classes. gettype() returns the type of a variable, i.e. string, int, object etc. If you want to know the class, use get_class(). Note that this will return the fully qualified classname, i.e. ProcessWire\PageArray. If you want to get the classname without the namespace, you can also use Wire::className, which is a method available on all classes extending the Wire class (so pretty much all ProcessWire classes). This one gives you only the classname with the namespace by default:

$somePageArray->className(); // PageArray

 

  • Like 1
Link to comment
Share on other sites

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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...