On Fri, Oct 2, 2009 at 10:46 AM, Nicolai Scheer <sc...@planetavent.de>wrote:

> Hi!
>
> Mathieu Suen schrieb:
> > Hi,
> >
> > I would like to know if there is some documentation on the different
> > layout of the array, object varaible ... in php.
> > Or were in the source can we read how the php VM reprensent those
> entites?
>
> At first, you should have a look at Zend/zend.h in the php source tree.
> There you'll find the definition of a "php variable", the zval struct:
>
> struct _zval_struct {
>        /* Variable information */
>        zvalue_value value;             /* value */
>        zend_uint refcount__gc;
>        zend_uchar type;        /* active type */
>        zend_uchar is_ref__gc;
> };
>
> The content of the variable is:
>
> typedef union _zvalue_value {
>        long lval;                                      /* long value */
>        double dval;                            /* double value */
>        struct {
>                char *val;
>                int len;
>        } str;
>        HashTable *ht;                          /* hash table value */
>        zend_object_value obj;
> } zvalue_value;
>
> Since a php variable can contain any type php has to offer, this
> representation was choosen in order to simplify access on the internal
> side.
>
> There's a bunch of macros for creating zvals, getting/setting
> types/values, etc. so you don't need to do this by hand (of course, in
> complex cases you have to).
>
> Does this help?
>
> greetings,
>
> Nico
>
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

Hello,

As Mathieu advised, taking a look at some of the source code would be very
helpful

You should also take a look at these files in the Zend folder of the PHP
source:

zend_object_handlers.c
zend_object_handlers.h
zend_objects.c
zend_objects.h
zend_objects_API.c
zend_objects_API.h

After that, I would advice that you grab a copy of Sara Golemon's book. It
was really helpful to me as well.

*http://www.amazon.com/Extending-Embedding-PHP-Sara-Golemon/dp/067232704X*

One similarity between arrays and objects is that they both use the
HashTable type to store their elements (for arrays) and properties (for
objects).

For objects (classes), however the class has to be made available during the
MINIT phase whereas for arrays that is not needed.

There are other similarities and differences but Sara Goleman's book will
definitely give you a head start and then you can figure out the rest as you
practice.

There are also differences between PHP 5.2 and 5.3, they use fifferent
versions of the Zend Engine (2.2 and 2.3 respectively) some members of the
zval struct have changed and you will need to use the macros to access some
of the members of these structs for compatibility reasons.

-- 
"Good Enough" is not good enough.
To give anything less than your best is to sacrifice the gift.
Quality First. Measure Twice. Cut Once.

Reply via email to