# using zend_parse_parameters to get an object of an externally defined class

- Thread: https://externals.io/message/32488
- Original archive: https://news-web.php.net/php.internals/32488
- Started by alon on 2007-09-28T10:57:34+00:00
- Messages: 3
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #32488 — alon — 2007-09-28T10:57:34+00:00

URL: https://externals.io/message/32488#32488

A newbie question:

How can I use zend_parse_parameters to accept object of an external class as 
parametr.

I want for example to build a method that accepts 'DateTime' objects. I know 
that the syntax of zend_parse_parameters is something like:

zval *obj;
zend_class_entry ce;
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
                          "O", &obj, ce, &d) == FAILURE) {
    return;
}

But how do I initiate the zend_class_entry to specify an object of the 
DateTime class?

---

## #32490 — Michael Wallner — 2007-09-28T11:21:46+00:00

URL: https://externals.io/message/32488#32490 · In reply to: #32488

alon wrote:
> A newbie question:
> 
> How can I use zend_parse_parameters to accept object of an external class as 
> parametr.
> 
> I want for example to build a method that accepts 'DateTime' objects.

> But how do I initiate the zend_class_entry to specify an object of the 
> DateTime class?

The class entry pointer or a function which returns it needs to be
exported by the datetime API.  IIRC that's not the case ATM.

-- 
Michael

---

## #32493 — johannes@php.net — 2007-09-28T14:04:14+00:00

URL: https://externals.io/message/32488#32493 · In reply to: #32490

Hi,


> alon wrote:
> > […]
> 
> > […]
> 
> The class entry pointer or a function which returns it needs to be
> exported by the datetime API.  IIRC that's not the case ATM.
> 

you can also get the ce using zend_fetch_class() API function. So the
code would look something like

zend_class_entry *ce = zend_fetch_class("DateTime",
   sizeof("DateTime")-1, ZEND_FETCH_CLASS_DEFAULT TSRMLS_CC);

if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC,
                          "O", &obj, ce) == FAILURE) {
    return;
}

When referencing an internal class it should be enough to do the fetch
just once and cache the value inside your extension.

> -- 
> Michael
