Re: Detect zval instance of class/subclass
| From: | Johannes Schlüter | Date: | Thu, 23 Sep 2010 10:38:39 +0000 |
| Subject: | Re: Detect zval instance of class/subclass | ||
| References: | 1 | Groups: | php.pecl.dev |
| Request: | Send a blank email to pecl-dev+get-7678@lists.php.net to get a copy of this message | ||
Hi
On Wed, 2010-09-22 at 19:35 +0100, Mark Skilbeck wrote:
> Hi, all.
>
> I was wondering - supposing a function takes a parameter that can be
> either TypeA or TypeB, or any subclass thereof, what is the best way
> to check for this requirement? Initially I was just comparing the names
> in the class entry, but, of course, that won't work for subclassed objects.
See README.PARAMETER_PARSING_API from the php-src:
[...]
O - object of specific type given by class entry (zval*, zend_class_entry)
[...]
/* Gets an object of class specified by my_ce, and an optional double. */
zval *obj;
double d = 0.5;
zend_class_entry *my_ce;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "O|d",
&obj, my_ce, &d) == FAILURE) {
return;
}
johannes