Macros

Zend Engine 2 Macros

FAILURE

Used to indicate failure

This is an alias for -1

INIT_CLASS_ENTRY()

Convienience macro for setting the properties of a simple class entry

INIT_CLASS_ENTRY(class_container, class_name, functions)

type parameter description
zend_class_entry class_container The container in which to store this class type
char* class_name The name of the class as seen in userspace
zend_function_entry[] functions Array of methods

You should use this macro to set class entry properties when you do not need to specify methods for equivalents to __get(), __set(), __call(), __isset(), or __unset().

This is an alias for INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, NULL, NULL, NULL)

Example:

zend_class_entry ce;
INIT_CLASS_ENTRY(ce,"myClass",myClass_methods);

INIT_OVERLOADED_CLASS_ENTRY()

Convienience macro for setting the properties of a fairly simple class entry

INIT_OVERLOADED_CLASS_ENTRY(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset)

type parameter description
zend_class_entry class_container The container in which to store this class type
char* class_name The name of the class as seen in userspace
zend_function_entry[] functions Array of methods
handle_fcall
handle_propget
handle_propset

You should use this macro to set class entry properties when you do not need to specify methods for equivalents to __isset() or __unset().

This is an alias for INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset, NULL, NULL)

INIT_OVERLOADED_CLASS_ENTRY_EX()

Sets the properties of a class container

INIT_OVERLOADED_CLASS_ENTRY_EX(class_container, class_name, functions, handle_fcall, handle_propget, handle_propset, handle_propunset, handle_propisset)

Parameters:

type parameter description
zend_class_entry class_container The container in which to store this class type
char* class_name The name of the class as seen in userspace
zend_function_entry[] functions Array of methods
handle_fcall
handle_propget
handle_propset
handle_propunset
handle_propisset

In addition to the container properties that can be set using the parameters of this macro, several others are initialized.
Here is the complete list:

INTERNAL_FUNCTION_PARAMETERS

Alias for the standard parameters for an internal function

This is an alias for int ht, zval *return_value, zval **return_value_ptr, zval *this_ptr, int return_value_used TSRMLS_DC

INTERNAL_FUNCTION_PARAM_PASSTHRU

Used to provide the values given by INTERNAL_FUNCTION_PARAMETERS

This is an alias for ht, return_value, return_value_ptr, this_ptr, return_value_used TSRMLS_CC

IS_ARRAY

Indicates that a zval contains a array of values

An array zval is equivalent to an array of values in userspace

This is an alias for 4

IS_BOOL

Indicates that a zval contains a Boolean value

A bool zval is equivalent to a bool value in userspace

This is an alias for 3

IS_CONSTANT

Indicates that a zval contains a constant value

A constant zval is equivalent to a constant value in userspace

This is an alias for 8

IS_DOUBLE

Indicates that a zval contains a double percision floating point value

A double zval is equivalent to a float value in userspace

This is an alias for 2

IS_LONG

Indicates that a zval contains a long integer value

A long zval is equivalent to an integer value in userspace

This is an alias for 1

IS_NULL

Indicates that a zval contains a NULL value

A NULL zval is equivalent to a null value in userspace

This is an alias for 0

IS_OBJECT

Indicates that a zval contains an object

An object zval is equivalent to an object in userspace

This is an alias for 5

IS_RESOURCE

Indicates that a zval contains a resource

A resource zval is equivalent to a resource in userspace

This is an alias for 7

IS_STRING

Indicates that a zval contains a string value

A string zval is equivalent to a string value in userspace

This is an alias for 6

LONG_MAX

The maximum value of a long integer

LONG_MAX

If not already defined by the compiler, this will be set to 2147483647

LONG_MIN

The minimum value of a long integer

LONG_MIN

If not already defined, this is set to the inverse of LONG_MAX-1

PHP_FN()

Used to prepend zif_ to a function name

PHP_FN(name)

type parameter description
text name name of the function

The reason zif_ should be added to zend internal function names is to avoid name conflicts.

Use of this macro is recomended over adding zif_ to the actual function names to ensure future compatibility.

zif stands for Zend Internal Function

This is an alias for "ZEND_FN(name)"

PHP_MN()

Used to prepend zim_ to a method name

PHP_MN(name)

type parameter description
text name name of the method

The reason zim_ should be added to zend internal method names is to avoid name conflicts.

Use of this macro is recomended over adding zim_ to the actual method names to ensure future compatibility.

zim stands for Zend Internal Method

This is an alias for "ZEND_MN(name)"

SUCCESS

Used to indicate success

SUCCESS

This is an alias for 0

TSRMLS_C

Used to pass a pointer to the current thread to a function

Generally you will use this with TSRMLS_D or TSRMLS_DC which are used to recieve this info in a function definition

This is esentially the same as TSRMLS_CC without the built-in preceding comma

This is an alias for tsrm_ls

TSRMLS_CC

Used to pass a pointer to the current thread to a function

Generally you will use this with TSRMLS_D or TSRMLS_DC which are used to recieve this info in a function definition

This is esentially the same as TSRMLS_C except it includes a preceding comma

This is an alias for , TSRMLS_C

TSRMLS_D

Used to recieve a pointer to the current thread in a function definition

Generally you will use this with TSRMLS_C or TSRMLS_CC which are used to pass this info to a function

This is esentially the same as TSRMLS_DC except without the built-in preceding comma

This is an alias for void ***tsrm_ls

TSRMLS_DC

Used to recieve a pointer to the current thread in a function definition

Generally you will use this with TSRMLS_C or TSRMLS_CC which are used to pass this info to a function

This is esentially the same as TSRMLS_D except it includes a preceding comma

This is an alias for , TSRMLS_D

ZEND_ABSTRACT_ME()

Convenience macro for defining an abstract method in a ZEND_FENTRY(name, NULL, arg_info, ZEND_ACC_PUBLIC|ZEND_ACC_ABSTRACT)"

Example:

static zend_function_entry function_methods[] = {
PHP_ABSTRACT_ME(myClass,overloadMe,NULL)
{ NULL, NULL, NULL }
};

ZEND_ACC_ABSTRACT

Identifies an abstract method

An abstract method cannot be called, it can only be overloaded

This is an alias for 0x02

ZEND_ACC_FINAL

Identifies a final method

Methods marked as final cannot be overloaded

This is an alias for 0x04

ZEND_ACC_IMPLEMENTED_ABSTRACT

Identifies a method which overloads an abstract method

This is an alias for 0x08

ZEND_ACC_PPP_MASK

Used when testing method visibility

This is an alias for (ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE)

ZEND_ACC_PRIVATE

Indicates a method has private access

Methods declared private can be accessed only inside of the class in which they are declared

This is an alias for 0x400

ZEND_ACC_PROTECTED

Indicates a method has protected access

Methods declared protected can be accessed only inside of the class in which in is declared or in derived classes

This is an alias for 0x200

ZEND_ACC_PUBLIC

Indicates a method has public access

Methods declared public can be accessed both inside and outside of a class instance

This is an alias for 0x100

ZEND_ACC_STATIC

Identifies a static method

Static methods do not need an instance of the class, but cannot use data that relies on non static class data. Because static methods are not tied to an instance of an object, you cannot use a ->, you must use ::

This is an alias for 0x01

Example: (PHP userspace code)

class a {
public static function bob() {
return "fred";
}
}

echo a::bob();

ZEND_API

Used to indicate that a function is part of the Zend API

This is only used for code documentation scanners and does nothing whatsoever code-wise

ZEND_FENTRY()

Define a function for use in a zend_function_entry

ZEND_FENTRY(zend_name, name, arg_info, flags)

type parameter description
text zend_name userspace name of the function
text internal name of the function
zend_arg_info* arg_info
zend_uint num_args number of arguments
zend_uint flags

Alias for "{ #zend_name, name, arg_info, (zend_uint) (sizeof(arg_info)/sizeof(struct _zend_arg_info)-1), flags },"

ZEND_FILE_LINE_C

Used to pass the file name and line number of the file being parsed to a function

Generally you will use this with ZEND_FILE_LINE_D or ZEND_FILE_LINE_DC, which are used to request this info in a function definition

This is esentially the same as ZEND_FILE_LINE_CC without the built-in preceding comma

If ZEND_DEBUG is not defined, this macro does nothing

This is an alias for __FILE__, __LINE__

ZEND_FILE_LINE_D

Used to request the file name and line number of the file being parsed in a function definition

Generally you will use this with ZEND_FILE_LINE_C, ZEND_FILE_LINE_CC, ZEND_FILE_LINE_EMPTY_C, or ZEND_FILE_LINE_EMPTY_CC which are used to pass this info to a function

This is esentially the same as ZEND_FILE_LINE_DC without the built-in preceding comma

If ZEND_DEBUG is not defined, this macro does nothing

This is an alias for char *__zend_filename, uint __zend_lineno

ZEND_FILE_LINE_DC

Used to request the file name and line number of the file being parsed in a function definition

Generally you will use this with ZEND_FILE_LINE_C, ZEND_FILE_LINE_CC, ZEND_FILE_LINE_EMPTY_C, or ZEND_FILE_LINE_EMPTY_CC which are used to pass this info to a function

This is esentially the same as ZEND_FILE_LINE_D with a built-in preceding comma

If ZEND_DEBUG is not defined, this macro does nothing

This is an alias for , ZEND_FILE_LINE_D

ZEND_FN()

Used to prepend zif_ to a function name

ZEND_FN(name)

type parameter description
text name name of the function

The reason zif_ should be added to zend internal function names is to avoid name conflicts.

Use of this macro is recomended over adding zif_ to the actual function names to ensure future compatibility.

zif stands for Zend Internal Function

This is an alias for "zif_##name"

ZEND_FUNCTION

expands to
ZEND_FUNCTION(name) ZEND_NAMED_FUNCTION(ZEND_FN(name))

ZEND_GCC_VERSION

Used in other macros to determine the version of GCC used

If not compiling with GCC, this is set to 0, otherwise this is an alias for (__GNUC__ * 1000 + __GNUC_MINOR__)

ZEND_MALIAS()

Create a method that is an alias for antother method in a zend_function_entry

ZEND_MALIAS(classname, name, alias, arg_info, flags)

type parameter description
text classname userpace name of the class of which this method will be a member
text name userspace name of this method
text alias userspace name of the method for which this method will be an alias
zend_arg_info* arg_info
zend_uint flags

Alias for "ZEND_FENTRY(name, ZEND_MN(classname##_##alias), arg_info, flags)"

Example:

static zend_function_entry function_methods[] = {
PHP_ME(myClass,funcOne,NULL,ZEND_ACC_PUBLIC)
PHP_MALIAS(myClass,funcTwo,funcOne,NULL,ZEND_ACC_PUBLIC)
{ NULL, NULL, NULL }
};

ZEND_ME()

Define a simple class method entry for use in a zend_function_entry

ZEND_ME(classname, name, arg_info, flags)

type parameter description
text classname name of the userspace class
text name userspace name of the method
zend_arg_info* arg_info
zend_uint flags

Note: the classname and name parameters should be straight text, not a char*

This is an alias for "ZEND_FENTRY(name, ZEND_MN(classname##_##name), arg_info, flags)"

Example:

static zend_function_entry function_methods[] = {
PHP_ME(myClass,myMethod,NULL,ZEND_ACC_PUBLIC)
{ NULL, NULL, NULL }
};

ZEND_MN()

Used to prepend zim_ to a method name

ZEND_FM(name)

type parameter description
text name name of the method

The reason zim_ should be added to zend internal method names is to avoid name conflicts.

Use of this macro is recomended over adding zim_ to the actual method names to ensure future compatibility.

zim stands for Zend Internal Method

This is an alias for "zim_##name"

ZEND_NAMED_FUNCTION

expands to

#define ZEND_NAMED_FUNCTION(name) void name(INTERNAL_FUNCTION_PARAMETERS)

ZEND_NUM_ARGS()

Used to pass the number of parameters given to a function or method

ZEND_NUM_ARGS()

This macro should always be used to pass the number of parameters when using Zend API functions like zend_parse_parameters

This is an alias for (ht)

Z_ARRVAL()

Used to get the hash table contained in a zval

Z_ARRVAL(zval)

Returns:

HashTable*

Parameters:

type parameter description
zval zval the zval container from which to get the hash table

This will not convert the data to a hash table

This macro is for use on zval variables, for zval* use Z_ARRVAL_P and for zval** use Z_ARRVAL_PP

This is an alias for (zval).value.ht

Z_BVAL()

Used to get the Boolean data contained in a zval

Z_BVAL(zval)

Parameters:

type parameter description
zval zval the zval container from which to get a Boolean value

This will not convert the data to a bool

This macro is for use on zval variables, for zval* use Z_BVAL_P and for zval** use Z_BVAL_PP

This is an alias for ((zend_bool)(zval).value.lval)

Z_DVAL()

Used to get the double contained in a zval

Z_DVAL(zval)

Parameters:

type parameter description
zval zval the zval container from which to get a double

This will not convert the data to a double

This macro is for use on zval variables, for zval* use Z_DVAL_P and for zval** use Z_DVAL_PP

This is an alias for (zval).value.dval

Z_LVAL()

Used to get the long data contained in a zval

Z_LVAL(zval)

Parameters:

type parameter description
zval zval the zval container from which to get a long value

This will not convert the data to a long

This macro is for use on zval variables, for zval* use Z_LVAL_P and for zval** use Z_LVAL_PP

This is an alias for (zval).value.lval

Z_OBJCE()

Used to get the class entry of the object contained in a zval

Z_OBJCE(zval)

Returns:

zend_class_entry

Parameters:

type parameter description
zval zval the zval container from which to get the zend_class_entry

This will not convert the data to an object

This macro is for use on zval variables, for zval* use Z_OBJCE_P and for zval** use Z_OBJCE_PP

This is an alias for zend_get_class_entry(&(zval) TSRMLS_CC)

Z_OBJVAL()

Used to get a zend_object_value contained in a zval

Z_OBJVAL(zval)

Returns:

zend_object_value*

Parameters:

type parameter description
zval zval the zval container from which to get the zend_object_value

This will not convert the data to an object

This macro is for use on zval variables, for zval* use Z_OBJVAL_P and for zval** use Z_OBJVAL_PP

This is an alias for (zval).value.obj

Z_OBJ_HANDLE()

Used to get a zend_object_handle contained in a zval

Z_OBJ_HANDLE(zval)

Returns:

zend_object_handle*

Parameters:

type parameter description
zval zval the zval container from which to get the zend_object_handle

This will not convert the data to an object

This macro is for use on zval variables, for zval* use Z_OBJ_HANDLE_P and for zval** use Z_OBJ_HANDLE_PP

This is an alias for Z_OBJVAL(zval).value.handle

Z_OBJ_HT()

Used to get the zend_object_handlers contained in a zval

Z_OBJ_HT(zval)

Returns:

zend_object_handlers*

Parameters:

type parameter description
zval zval the zval container from which to get the zend_object_handlers

This will not convert the data to an object

This macro is for use on zval variables, for zval* use Z_OBJ_HT_P and for zval** use Z_OBJ_HT_PP

This is an alias for Z_OBJVAL(zval).handlers

Z_STRLEN()

Used to get the length of the string data contained in a zval

Z_STRLEN(zval)

Returns:

int

Parameters:

type parameter description
zval zval the zval container from which to get the length a string value

This will not convert the data to a string or int

This macro is for use on zval variables, for zval* use Z_STRLEN_P and for zval** use Z_STRLEN_PP

This is an alias for (zval).value.str.len

Z_STRVAL()

Used to get the string data contained in a zval

Z_STRVAL(zval)

Parameters:

type parameter description
zval zval the zval container from which to get a string value

This will not convert the data to a bool

This macro is for use on zval variables, for zval* use Z_BVAL_P and for zval** use Z_BVAL_PP

This is an alias for (zval).value.str.val