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
https://forums.phpfreaks.com/topic/102839-solved-determining-the-type-of-object/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.