NAME ^

src/pmc/phparray.pmc - PHP Array

DESCRIPTION ^

VTABLE Functions ^

void init()

Intialize this PHPArray.

void init_pmc(PMC *p)

Initialize this PHPArray with the passed-in PMC p. If p is a PHPArray, its contents are copied directly. If p is a PMC that provides a hash or array interface, its contents are copied via the appropriate VTABLE functions. In any other case, an exception will be thrown.

void destroy()

Non-recursively free all memory used by this PHPArray.

void mark()

Recursively mark this PHPArray and all its contents as live.

INTVAL elements()

Return the number of elements in this PHPArray.

void set_integer_keyed(PMC *key, INTVAL i_val)

Store i_val in this PHPArray, indexed by the Key PMC key.

void set_integer_keyed_str (STRING *s_key, INTVAL i_val)

Store i_val in this PHPArray, indexed by the STRING s_key.

void set_integer_keyed_int (INTVAL i_key, INTVAL i_val)

Store i_val in this PHPArray, indexed by the INTVAL i_key.

void set_pmc_keyed(PMC *key, PMC *p_val)

Store val in this PHPArray, indexed by the Key PMC key.

void set_pmc_keyed_str(STRING *s_key, PMC *val)

Store val in this PHPArray, indexed by the STRING s_key.

void set_pmc_keyed_int(INTVAL i_key, PMC *val)

Store val in this PHPArray, indexed by the INTVAL i_key.

void set_string_keyed(PMC *key, STRING *s_val)

Store s_val in this PHPArray, indexed by the Key PMC key.

void set_string_keyed_str(STRING *s_key, STRING *s_val)

Store s_val in this PHPArray, indexed by the STRING s_key.

void set_string_keyed_int(INTVAL i_key, STRING *s_val)

Store s_val in this PHPArray, indexed by the INTVAL i_key.

void set_number_keyed(PMC *key, FLOATVAL f_val)

Store f_val in this PHPArray, indexed by the Key PMC key.

void set_number_keyed_str(STRING *s_key, FLOATVAL f_val)

Store f_val in this PHPArray, indexed by the STRING s_key.

void set_number_keyed_int(INTVAL i_key, FLOATVAL f_val)

Store f_val in this PHPArray, indexed by the INTVAL i_key.

INTVAL get_integer_keyed(PMC *key)

Retrieve the value from this PHPArray which is associated with the Key PMC key.

INTVAL get_integer_keyed_str(STRING *s_key)

Retrieve the value from this PHPArray which is associated with the STRING s_key.

INTVAL get_integer_keyed_int(INTVAL i_key)

Retrieve the value from this PHPArray which is associated with the INTVAL i_key.

PMC *get_pmc_keyed(PMC *key)

Retrieve the value from this PHPArray which is associated with the Key PMC key.

PMC *get_pmc_keyed_str(STRING *s_key)

Retrieve the value from this PHPArray which is associated with the STRING s_key.

PMC *get_pmc_keyed_int(INTVAL i_key)

Retrieve the value from this PHPArray which is associated with the INTVAL i_key.

STRING *get_string_keyed(PMC *key)

Retrieve the value from this PHPArray which is associated with the Key PMC key.

STRING *get_string_keyed_str(STRING *s_key)

Retrieve the value from this PHPArray which is associated with the STRING s_key.

STRING *get_string_keyed_int(INTVAL i_key)

Retrieve the value from this PHPArray which is associated with the INTVAL i_key.

FLOATVAL get_number_keyed(PMC *key)

Retrieve the value from this PHPArray which is associated with the Key PMC key.

FLOATVAL get_number_keyed_str(STRING *s_key)

Retrieve the value from this PHPArray which is associated with the STRING s_key.

FLOATVAL get_number_keyed_int(INTVAL i_key)

Retrieve the value from this PHPArray which is associated with the INTVAL i_key.

INTVAL exists_keyed(PMC *key)

Return non-zero if an element keyed by key exists.

INTVAL exists_keyed_str(STRING *s_key)

Return non-zero if an element keyed by s_key exists.

INTVAL exists_keyed_int(INTVAL i_key)

Return non-zero if an element keyed by i_key exists.

void delete_keyed(PMC *key)

If an element in this PHPArray is keyed by key, delete it. Otherwise do nothing.

void delete_keyed_str(STRING *s_key)

If an element in this PHPArray is keyed by key, delete it. Otherwise do nothing.

void delete_keyed_int(INTVAL i_key)

If an element in this PHPArray is keyed by key, delete it. Otherwise do nothing.

void push_integer(INTVAL i)

Add an integer with the value i to the end of this PHPArray.

void push_pmc(PMC *p_val)

Add a PMC with the value p_val to the end of this PHPArray.

void push_string(STRING *s_val)

Add a STRING with the value s_val to the end of this PHPArray.

void push_float(FLOATVAL f_val)

Add a FLOATVAL with the value f_val to the end of this PHPArray.

INTVAL pop_integer()

Delete the element at the end of this PHPArray, returning its value as an INTVAL.

PMC *pop_pmc()

Delete the element at the end of this PHPArray, returning its value as a PMC.

STRING *pop_string()

Delete the element at the end of this PHPArray, returning its value as a STRING.

FLOATVAL pop_float()

Delete the element at the end of this PHPArray, returning its value as a FLOATVAL.

void unshift_integer(INTVAL i_val)

Add an integer with the value i_val to the beginning of this PHPArray. i_val will be keyed by the INTVAL 0 and all other numerically indexed elements will be renumbered according to insertion order.

void unshift_pmc(PMC *p_val)

Add a PMC with the value p_val to the beginning of this PHPArray. p_val will be keyed by the INTVAL 0 and all other numerically indexed elements will be renumbered according to insertion order.

void unshift_string(STRING *s_val)

Add a STRING with the value s_val to the beginning of this PHPArray. s_val will be keyed by the INTVAL 0 and all other numerically indexed elements will be renumbered according to insertion order.

void unshift_float(FLOATVAL f_val)

Add a FLOATVAL with the value f_val to the beginning of this PHPArray. f_val will be keyed by the INTVAL 0 and all other numerically indexed elements will be renumbered according to insertion order.

INTVAL shift_integer()

Delete the element at the beginning of this PHPArray, returning its value as an INTVAL.

PMC *shift_pmc()

Delete the element at the beginning of this PHPArray, returning its value as a PMC.

STRING *shift_string()

Delete the element at the beginning of this PHPArray, returning its value as a STRING.

FLOATVAL shift_float()

Delete the element at the beginning of this PHPArray, returning its value as a FLOATVAL.

STRING *name()

Return the string 'array'.

STRING *get_string()

Return the string 'Array'.

INTVAL get_bool()

Return 1 if this PHPArray has 1 or more elements.

void visit(visit_info *info()

Freeze or thaw the contents of this PHPArray.

void freeze(visit_info *info()

After visit() has been called during the freeze process, this VTABLE function is used to add additional information about the PHPArray to the visit_info struct.

void thaw(visit_info *info()

Before visit() is called during the thaw process, this VTABLE function is used to initialize the empty PHPArray.

void thawfinish(visit_info *info()

After visit() is called during the thaw process, this VTABLE function is used to make any changes to the newly thawed PHPArray which could not be made during the thaw process.

PMC *get_iter()

Return an Iterator over this PHPArray. When using an Iterator over PHPArrays, it is a very good idea to use the iter opcode as follows:

 $P0 = new 'PhpArray'
 $P1 = iter $P0
This ensures that the Iterator and the PHPArray's internal pointer stay in sync. Using an Iterator and a PHPArray any other way may lead to mysterious failures.

PMC *clone()

Return a deep clone of this PHPArray.

void assign_pmc(PMC *src)

If src is an aggregate PMC (i.e. one that does hash and/or array), use an Iterator to copy each key/value pair into this PHPArray. If src is a PHPArray, just make a clone.

PMC *add(PMC *src, PMC *dest)

Copy all key/value pairs in SELF and src into dest. All values in dest are deleted. If the same key is in both src and SELF, the value from SELF will be used.

PMC *i_add(PMC *src)

Copy all key/value pairs from src into SELF. If the same key is in both src and SELF, the value from SELF will be used.

INTVAL is_equal(PMC *other)

Return true if SELF and other contain the same key/value pairs and have the same number of elements. Order is not important.

INTVAL is_equal_num(PMC *other)

Determine equality between a PHPArray and a number. PHP's documentation says that an array is always greater than a number, so this function returns 0. See http://us.php.net/manual/en/language.operators.comparison.php .

INTVAL is_equal_string(PMC *other)

Determine equality between a PHPArray and a string. PHP's documentation says that an array is always greater than a string, so this function returns 0. See http://us.php.net/manual/en/language.operators.comparison.php .

INTVAL is_same(PMC *other)

Return true if SELF and other point to the same place in memory.

INTVAL cmp(PMC *other)

Compare SELF to other. A PHPArray with fewer elements is always considered to be less than one with more elements. Two PHPArrays of the same size are comparable if they have the same keys. In this case, a > b if the first unequal value of a is greater, according to the internal ordering of a. This means it's possible for both a > b and b > a to be true.

If the arrays are comparable and SELF is larger, cmp returns 1. If they're equal, cmp returns 0. If other is larger, cmp returns -1.

If SELF and the other PMC are not comparable, an exception is thrown. This is to allow the PHP implementation to return null for a comparison between two non-comparable PHPArrays.

INTVAL cmp_num(PMC *other)

In PHP, arrays are always greater than numeric types. This function always returns 1.

INTVAL cmp_string(PMC *other)

In PHP, arrays are always greater than strings. This function always returns 1.

STRING *get_repr()

Return a string representation of the contents of this PhpArray. The format of this string is the same as a Parrot Hash's get_repr():

 {0: 4, 4: 323, 'foo': 9999999}

Methods ^

METHOD void next()

Advance the internal pointer to the next element. This method emulates the behavior of PHP's next() function.

METHOD void prev()

Move the internal pointer to the previous element. This method emulates the behavior of PHP's prev() function.

METHOD void reset()

Move the internal pointer to the first element of this PhpArray, according to insertion order. This method emulates the behavior of PHP's reset() function.

METHOD void end()

Move the internal pointer to the last element of this PhpArray, according to insertion order. This method emulates the behavior of PHP's end() function.

METHOD STRING *key()

Return the key of the element pointed to by the internal pointer. If the internal pointer does not point at a valid element, the empty string is returned. This method has no side-effects and does not modify the internal pointer.

METHOD PMC *current()

Return a clone of value of the element pointed to by the internal pointer. If the internal pointer does not point at a valid element, PMCNULL is returned. This method has no side-effects and does not modify the internal pointer.

METHOD PMC *each()

Return a PhpArray containing the key/value pair pointed to by the internal pointer, then advance the internal pointer to the next pair. The returned PhpArray has the following key/value pairs, in this order:

where key and value are the key and value from this PhpArray. If the internal pointer does not point to a valid element, a PhpBoolean false will be returned.

PMC *to_number()

METHOD void sanity_check()

Check if everything about the PippHashTable looks sane. If anything looks broken, the code will throw an exception.

AUTHORS ^

Christoph Otto

Francois Perrad


parrot