Jump to content

[SOLVED] Determining the type of object


mabus

Recommended Posts

I usually user php's "assert" function to test variables.

 

Now, is there a way to determine the type of object that is initialized to a variable? The function "is_object" is not good enough, 'cause it will only determine a particular variable or not, but what I want is to determine if a particular object satisfies the set requirement.

 

for example:

 

public function GetSomething(MyDesiredObject $newObject) {

... some implementation here ...

}

 

Now, I want this function to be able to accept only that "MyDesiredObject" data type. usually I'd do an assert from within the function to test, but how about if I want to determine if the value of that "$newObject" variable is really of "MyDesiredObject" data type?

 

How do we do this on PHP?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.