Skip to content

Commit

Permalink
stop supporting php4
Browse files Browse the repository at this point in the history
  • Loading branch information
zenovich committed Jan 17, 2015
1 parent 27f33f5 commit acdbb2f
Show file tree
Hide file tree
Showing 46 changed files with 55 additions and 913 deletions.
4 changes: 2 additions & 2 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,15 @@ Bar is 2
Baz is


Compatability: PHP 4.2 or greater
Compatability: PHP 5.0 or greater


[USER DEFINED FUNCTION AND CLASS MANIPULATION]
Userdefined functions and userdefined methods may now be renamed, delete, and redefined using the API described at http://www.php.net/runkit

Examples for these functions may also be found in the tests folder.

Compatability: PHP4 and PHP5
Compatability: PHP5


[SANDBOXING]
Expand Down
16 changes: 2 additions & 14 deletions package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Execute code in restricted environment (sandboxing).
<active>yes</active>
</lead>

<date>2013-05-12</date>
<date>2015-01-17</date>
<version>
<release>1.0.4</release>
<api>1.0.4</api>
Expand All @@ -30,6 +30,7 @@ Execute code in restricted environment (sandboxing).
<notes>
New features:
+ PHP 5.4 is now fully supported
- PHP 4.x is not supported anymore
+ Introduced new function "runkit_default_property_remove" (Thanks to Juhan Kundla)
+ Ability to add non-scalar default properties was added
+ Magic methods __isset, __unset, __callStatic, and __toString are now supported.
Expand Down Expand Up @@ -208,26 +209,17 @@ Execute code in restricted environment (sandboxing).
<file name="bug4519.phpt" role="test" />
<file name="namespaces.phpt" role="test" />
<file name="runkit_default_property_add.phpt" role="test" />
<file name="runkit_default_property_add4.phpt" role="test" />
<file name="runkit_default_property_add_and_remove_for_class_with_dynamic_properties.phpt" role="test" />
<file name="runkit_default_property_add_to_subclasses.phpt" role="test" />
<file name="runkit_default_property_remove.phpt" role="test" />
<file name="runkit_default_property_remove_and_add_for_class_with_dynamic_properties.phpt" role="test" />
<file name="runkit_default_property_remove_and_reflection.phpt" role="test" />
<file name="runkit_default_property_remove_from_subclasses.phpt" role="test" />
<file name="runkit_default_property_remove_from_subclasses4.phpt" role="test" />
<file name="runkit_default_property_remove_inheritance.phpt" role="test" />
<file name="runkit_default_property_remove4.phpt" role="test" />
<file name="runkit_import_class4.inc" role="test" />
<file name="runkit_import_class4.phpt" role="test" />
<file name="runkit_import_class_property_not_overriding_subclasses.inc" role="test" />
<file name="runkit_import_class_property_not_overriding_subclasses.phpt" role="test" />
<file name="runkit_import_class_property_not_overriding_subclasses4.inc" role="test" />
<file name="runkit_import_class_property_not_overriding_subclasses4.phpt" role="test" />
<file name="runkit_import_class_property.inc" role="test" />
<file name="runkit_import_class_property.phpt" role="test" />
<file name="runkit_import_class_property4.inc" role="test" />
<file name="runkit_import_class_property4.phpt" role="test" />
<file name="runkit_import_non_existent_file.phpt" role="test" />
<file name="runkit_import_static_properties_override.inc" role="test" />
<file name="runkit_import_static_properties_override.phpt" role="test" />
Expand All @@ -240,21 +232,17 @@ Execute code in restricted environment (sandboxing).
<file name="runkit_superglobals.phpt" role="test" />
<file name="runkit_default_property_add_and_remove_for_class_with_dynamic_properties_overriding_in_objects.phpt" role="test" />
<file name="runkit_default_property_add_overriding_objects.phpt" role="test" />
<file name="runkit_default_property_add_overriding_objects4.phpt" role="test" />
<file name="runkit_default_property_add_to_subclasses_overriding_objects.phpt" role="test" />
<file name="runkit_default_property_remove_and_add_for_class_with_dynamic_properties_overriding_objects.phpt" role="test" />
<file name="runkit_default_property_remove_from_subclasses_overriding_objects.phpt" role="test" />
<file name="runkit_default_property_remove_inheritance_overriding_objects.phpt" role="test" />
<file name="runkit_default_property_remove_overriding_objects.phpt" role="test" />
<file name="runkit_default_property_remove_overriding_objects4.phpt" role="test" />
<file name="runkit_default_property_remove_private_and_inheritance.phpt" role="test" />
<file name="runkit_default_property_remove_private_and_inheritance_overriding_objects.phpt" role="test" />
<file name="runkit_default_property_remove_private_shadow_and_inheritance.phpt" role="test" />
<file name="runkit_default_property_remove_private_shadow_and_inheritance54.phpt" role="test" />
<file name="runkit_default_property_remove_private_shadow_and_inheritance_overriding_objects.phpt" role="test" />
<file name="runkit_import_class_property_and_inheritance_overriding_objects.phpt" role="test" />
<file name="runkit_import_function_overriding_objects4.inc" role="test" />
<file name="runkit_import_function_overriding_objects4.phpt" role="test" />
<file name="bug56662.phpt" role="test" />
<file name="bug56976.phpt" role="test" />
<file name="bug57249.inc" role="test" />
Expand Down
69 changes: 4 additions & 65 deletions php_runkit.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,19 +63,14 @@
#define PHP_RUNKIT_SANDBOX
#endif

/* Superglobals don't exist until PHP 4.2 */
#if (PHP_MAJOR_VERSION > 4 || (PHP_MAJOR_VERSION == 4 && PHP_MINOR_VERSION > 1)) && defined(PHP_RUNKIT_FEATURE_SUPER)
#define PHP_RUNKIT_SUPERGLOBALS
#endif

#ifdef PHP_RUNKIT_FEATURE_MODIFY
#define PHP_RUNKIT_MANIPULATION
#endif

#ifdef ZEND_ENGINE_2
# ifdef PHP_RUNKIT_MANIPULATION
#ifdef PHP_RUNKIT_MANIPULATION
#include "Zend/zend_object_handlers.h"
# endif
#endif

extern zend_module_entry runkit_module_entry;
Expand All @@ -88,9 +83,7 @@ PHP_RSHUTDOWN_FUNCTION(runkit);
PHP_MINFO_FUNCTION(runkit);

PHP_FUNCTION(runkit_return_value_used);
#ifdef ZEND_ENGINE_2
PHP_FUNCTION(runkit_object_id);
#endif

#ifdef PHP_RUNKIT_MANIPULATION
PHP_FUNCTION(runkit_function_add);
Expand Down Expand Up @@ -133,10 +126,8 @@ ZEND_BEGIN_MODULE_GLOBALS(runkit)
HashTable *misplaced_internal_functions;
HashTable *replaced_internal_functions;
zend_bool internal_override;
# ifdef ZEND_ENGINE_2
const char *name_str, *removed_method_str, *removed_function_str, *removed_parameter_str, *removed_property_str;
zend_function *removed_function, *removed_method;
# endif
#endif
ZEND_END_MODULE_GLOBALS(runkit)
#endif
Expand Down Expand Up @@ -186,7 +177,7 @@ extern ZEND_DECLARE_MODULE_GLOBALS(runkit);
#endif

#ifdef PHP_RUNKIT_MANIPULATION
#if defined(ZEND_ENGINE_2) && !defined(zend_hash_add_or_update)
#if !defined(zend_hash_add_or_update)
/* Why doesn't ZE2 define this? */
#define zend_hash_add_or_update(ht, arKey, nKeyLength, pData, pDataSize, pDest, flag) \
_zend_hash_add_or_update((ht), (arKey), (nKeyLength), (pData), (pDataSize), (pDest), (flag) ZEND_FILE_LINE_CC)
Expand All @@ -202,9 +193,8 @@ int php_runkit_check_call_stack(zend_op_array *op_array TSRMLS_DC);
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION > 5)
void php_runkit_clear_all_functions_runtime_cache(TSRMLS_D);
#endif
#ifdef ZEND_ENGINE_2

void php_runkit_remove_function_from_reflection_objects(zend_function *fe TSRMLS_DC);
#endif
void php_runkit_function_copy_ctor(zend_function *fe, const char *newname, int newname_len TSRMLS_DC);
int php_runkit_generate_lambda_method(const char *arguments, int arguments_len, const char *phpcode, int phpcode_len,
zend_function **pfe, zend_bool return_ref TSRMLS_DC);
Expand All @@ -217,9 +207,7 @@ int php_runkit_fetch_class(const char *classname, int classname_len, zend_class_
int php_runkit_fetch_class_int(const char *classname, int classname_len, zend_class_entry **pce TSRMLS_DC);
int php_runkit_clean_children_methods(RUNKIT_53_TSRMLS_ARG(zend_class_entry *ce), int num_args, va_list args, zend_hash_key *hash_key);
int php_runkit_update_children_methods(RUNKIT_53_TSRMLS_ARG(zend_class_entry *ce), int num_args, va_list args, zend_hash_key *hash_key);
#ifdef ZEND_ENGINE_2
int php_runkit_fetch_interface(const char *classname, int classname_len, zend_class_entry **pce TSRMLS_DC);
#endif

#if PHP_MAJOR_VERSION >= 6
#define PHP_RUNKIT_FUNCTION_ADD_REF(f) function_add_ref(f TSRMLS_CC)
Expand All @@ -234,8 +222,7 @@ int php_runkit_fetch_interface(const char *classname, int classname_len, zend_cl
#define PHP_RUNKIT_HASH_EXISTS(hash,param) zend_u_hash_exists(hash, param##_type, (UChar *)param, param##_len + 1)
#define PHP_RUNKIT_HASH_KEY(hash_key) ((hash_key)->type == HASH_KEY_IS_UNICODE ? (hash_key)->u.unicode : (hash_key)->u.string)
#define PHP_RUNKIT_HASH_KEYLEN(hash_key) ((hash_key)->type == HASH_KEY_IS_UNICODE ? UBYTES((hash_key)->nKeyLength) : (hash_key)->nKeyLength)

#elif PHP_MAJOR_VERSION >= 5
#else
#define PHP_RUNKIT_FUNCTION_ADD_REF(f) function_add_ref(f)
#define php_runkit_locate_scope(ce, fe, methodname_lower, methodname_len) fe->common.scope
#define PHP_RUNKIT_DECL_STRING_PARAM(p) char *p; int p##_len;
Expand All @@ -248,23 +235,6 @@ int php_runkit_fetch_interface(const char *classname, int classname_len, zend_cl
#define PHP_RUNKIT_HASH_EXISTS(hash,param) zend_hash_exists(hash, param##_type, param, param##_len + 1)
#define PHP_RUNKIT_HASH_KEY(hash_key) ((hash_key)->arKey)
#define PHP_RUNKIT_HASH_KEYLEN(hash_key) ((hash_key)->nKeyLength)

#else /* PHP4 */
#define PHP_RUNKIT_FUNCTION_ADD_REF(f) function_add_ref(f)
zend_class_entry *_php_runkit_locate_scope(zend_class_entry *ce, zend_function *fe, const char *methodname_lower, int methodname_len TSRMLS_DC);
#define php_runkit_locate_scope(ce, fe, methodname_lower, methodname_len) _php_runkit_locate_scope((ce), (fe), (methodname_lower), (methodname_len) TSRMLS_CC)
#define PHP_RUNKIT_DECL_STRING_PARAM(p) char *p; int p##_len;
#define PHP_RUNKIT_STRING_SPEC "s"
#define PHP_RUNKIT_STRING_PARAM(p) &p, &p##_len
#define PHP_RUNKIT_STRTOLOWER(p) php_strtolower(p, p##_len)
#define PHP_RUNKIT_STRING_LEN(param,addtl) (param##_len + (addtl))
#define PHP_RUNKIT_STRING_TYPE(param) IS_STRING
#define PHP_RUNKIT_HASH_FIND(hash,param,ppvar) zend_hash_find(hash, param, param##_len + 1, (void*)ppvar)
#define PHP_RUNKIT_HASH_EXISTS(hash,param) zend_hash_exists(hash, param##_type, param, param##_len + 1)
#define PHP_RUNKIT_HASH_KEY(hash_key) ((hash_key)->arKey)
#define PHP_RUNKIT_HASH_KEYLEN(hash_key) ((hash_key)->nKeyLength)
#define zend_function_dtor destroy_zend_function

#endif /* Version Agnosticism */

/* runkit_constants.c */
Expand All @@ -276,22 +246,15 @@ int php_runkit_class_copy(zend_class_entry *src, const char *classname, int clas
/* runkit_props.c */
int php_runkit_update_children_def_props(RUNKIT_53_TSRMLS_ARG(zend_class_entry *ce), int num_args, va_list args, zend_hash_key *hash_key);
int php_runkit_def_prop_add_int(zend_class_entry *ce, const char *propname, int propname_len, zval *copyval, long visibility, const char *doc_comment, int doc_comment_len, zend_class_entry *definer_class, int override, int override_in_objects TSRMLS_DC);
#ifdef ZEND_ENGINE_2
int php_runkit_def_prop_remove_int(zend_class_entry *ce, const char *propname, int propname_len, zend_class_entry *definer_class,
zend_bool was_static, zend_bool remove_from_objects, zend_property_info *parent_property TSRMLS_DC);
void php_runkit_remove_property_from_reflection_objects(zend_class_entry *ce, const char *prop_name, int prop_name_len TSRMLS_DC);
#else
int php_runkit_def_prop_remove_int(zend_class_entry *ce, const char *propname, int propname_len, zend_class_entry *definer_class,
zend_bool was_static, zend_bool remove_from_objects, void *parent_property TSRMLS_DC);
#endif

#ifdef ZEND_ENGINE_2
typedef struct _zend_closure {
zend_object std;
zend_function func;
HashTable *debug_info;
} zend_closure;
#endif
#endif /* PHP_RUNKIT_MANIPULATION */

#ifdef PHP_RUNKIT_SANDBOX
Expand Down Expand Up @@ -370,7 +333,6 @@ struct _php_runkit_sandbox_object {
} \
}

#ifdef ZEND_ENGINE_2
#if RUNKIT_ABOVE53
# define PHP_RUNKIT_ADD_MAGIC_METHOD(ce, lcmname, mname_len, fe, orig_fe) { \
if (!strncmp((lcmname), ZEND_CLONE_FUNC_NAME, (mname_len))) { \
Expand Down Expand Up @@ -599,29 +561,6 @@ struct _php_runkit_sandbox_object {
unsigned int ignore_visibility:1;
#endif
} reflection_object;
#else
#define PHP_RUNKIT_DESTROY_FUNCTION(fe) destroy_zend_function(fe);
#define PHP_RUNKIT_ADD_MAGIC_METHOD(ce, lcmname, mname_len, fe, orig_fe)
#define PHP_RUNKIT_DEL_MAGIC_METHOD(ce, fe) { \
zend_function *current_constr; \
if (zend_hash_find(&(ce)->function_table, (ce)->name, (ce)->name_length + 1, (void*) &current_constr) == SUCCESS && \
current_constr && current_constr->op_array.opcodes == (fe)->op_array.opcodes && (fe) != current_constr) { \
zend_hash_del(&ce->function_table, ce->name, ce->name_length+1); \
} \
}
#define PHP_RUNKIT_INHERIT_MAGIC(ce, fe, orig_fe, is_constr) { \
zend_function *current_constr = NULL; \
if (is_constr) { \
zend_hash_find(&(ce)->function_table, (ce)->name, (ce)->name_length + 1, (void*) &current_constr); \
} \
if (((orig_fe) && current_constr && current_constr->op_array.opcodes == (orig_fe)->op_array.opcodes) || \
(!(orig_fe) && (is_constr) && !current_constr) \
) { \
zend_hash_update(&ce->function_table, ce->name, ce->name_length + 1, (fe), sizeof(zend_function), NULL); \
function_add_ref(fe); \
} \
}
#endif /* ZEND_ENGINE_2 */
#endif /* PHP_RUNKIT_MANIPULATION */

#endif /* PHP_RUNKIT_H */
Expand Down
31 changes: 5 additions & 26 deletions runkit.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ PHP_FUNCTION(runkit_zval_inspect)
zend_function_entry runkit_functions[] = {

PHP_FE(runkit_zval_inspect, NULL)
#ifdef ZEND_ENGINE_2
PHP_FE(runkit_object_id, NULL)
#endif
PHP_FE(runkit_return_value_used, NULL)

#ifdef PHP_RUNKIT_SUPERGLOBALS
Expand Down Expand Up @@ -163,7 +161,6 @@ ZEND_GET_MODULE(runkit)
#endif

#ifdef PHP_RUNKIT_MANIPULATION
# ifdef ZEND_ENGINE_2
ZEND_FUNCTION(_php_runkit_removed_function) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "A function removed by runkit was somehow invoked");
}
Expand All @@ -189,7 +186,6 @@ static inline void _php_runkit_init_stub_function(char *name, void (*handler)(IN
#endif
(*result)->internal_function.module = &runkit_module_entry;
}
# endif
#endif

#if defined(PHP_RUNKIT_SANDBOX) || defined(PHP_RUNKIT_MANIPULATION)
Expand All @@ -202,7 +198,6 @@ static void php_runkit_globals_ctor(void *pDest TSRMLS_DC)
#ifdef PHP_RUNKIT_MANIPULATION
runkit_global->replaced_internal_functions = NULL;
runkit_global->misplaced_internal_functions = NULL;
# ifdef ZEND_ENGINE_2
runkit_global->name_str = "name";
runkit_global->removed_method_str = "__method_removed_by_runkit__";
runkit_global->removed_function_str = "__function_removed_by_runkit__";
Expand All @@ -211,7 +206,6 @@ static void php_runkit_globals_ctor(void *pDest TSRMLS_DC)

_php_runkit_init_stub_function("__function_removed_by_runkit__", ZEND_FN(_php_runkit_removed_function), &runkit_global->removed_function);
_php_runkit_init_stub_function("__method_removed_by_runkit__", ZEND_FN(_php_runkit_removed_method), &runkit_global->removed_method);
# endif
#endif
}
#endif
Expand Down Expand Up @@ -260,25 +254,16 @@ PHP_MINIT_FUNCTION(runkit)

REGISTER_LONG_CONSTANT("RUNKIT_ACC_RETURN_REFERENCE", PHP_RUNKIT_ACC_RETURN_REFERENCE, CONST_CS | CONST_PERSISTENT);

#ifdef ZEND_ENGINE_2
REGISTER_LONG_CONSTANT("RUNKIT_ACC_PUBLIC", ZEND_ACC_PUBLIC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RUNKIT_ACC_PROTECTED", ZEND_ACC_PROTECTED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RUNKIT_ACC_PRIVATE", ZEND_ACC_PRIVATE, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RUNKIT_ACC_STATIC", ZEND_ACC_STATIC, CONST_CS | CONST_PERSISTENT);
#else
REGISTER_LONG_CONSTANT("RUNKIT_ACC_PUBLIC", 0x100, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RUNKIT_ACC_PROTECTED", 0x200, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RUNKIT_ACC_PRIVATE", 0x400, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("RUNKIT_ACC_STATIC", 0x001, CONST_CS | CONST_PERSISTENT);
#endif
REGISTER_LONG_CONSTANT("RUNKIT_OVERRIDE_OBJECTS", PHP_RUNKIT_OVERRIDE_OBJECTS, CONST_CS | CONST_PERSISTENT);

#ifdef PHP_RUNKIT_CLASSKIT_COMPAT
#ifdef ZEND_ENGINE_2
REGISTER_LONG_CONSTANT("CLASSKIT_ACC_PUBLIC", ZEND_ACC_PUBLIC, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLASSKIT_ACC_PROTECTED", ZEND_ACC_PROTECTED, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLASSKIT_ACC_PRIVATE", ZEND_ACC_PRIVATE, CONST_CS | CONST_PERSISTENT);
#endif
REGISTER_STRING_CONSTANT("CLASSKIT_VERSION", PHP_RUNKIT_VERSION, CONST_CS | CONST_PERSISTENT);
REGISTER_LONG_CONSTANT("CLASSKIT_AGGREGATE_OVERRIDE", PHP_RUNKIT_IMPORT_OVERRIDE, CONST_CS | CONST_PERSISTENT);
#endif
Expand Down Expand Up @@ -314,10 +299,8 @@ PHP_MINIT_FUNCTION(runkit)
PHP_MSHUTDOWN_FUNCTION(runkit)
{
#ifdef PHP_RUNKIT_MANIPULATION
# ifdef ZEND_ENGINE_2
pefree(RUNKIT_G(removed_function), 1);
pefree(RUNKIT_G(removed_method), 1);
# endif
#endif
#if defined(PHP_RUNKIT_SUPERGLOBALS) || defined(PHP_RUNKIT_MANIPULATION)
UNREGISTER_INI_ENTRIES();
Expand Down Expand Up @@ -346,27 +329,23 @@ static void php_runkit_register_auto_global(char *s, int len TSRMLS_DC)
return;
}

#ifdef ZEND_ENGINE_2
if (zend_register_auto_global(s, len,
# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION >= 6)
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION >= 6)
0,
# endif
#endif
NULL TSRMLS_CC) == SUCCESS) {

# if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION >= 6)
#if (PHP_MAJOR_VERSION == 5 && PHP_MINOR_VERSION >= 4) || (PHP_MAJOR_VERSION >= 6)
if (zend_hash_find(CG(auto_globals), s, len + 1, (void *) &auto_global) != SUCCESS) {
php_error_docref(NULL TSRMLS_CC, E_ERROR, "Cannot locate the newly created autoglobal");
return;
}
auto_global->armed = 0;
# else
#else
/* This shouldn't be necessary, but it is */
zend_auto_global_disable_jit(s, len TSRMLS_CC);

# endif
#else
if (zend_register_auto_global(s, len TSRMLS_CC) == SUCCESS) {
#endif // ZEND_ENGINE_2
#endif

if (!RUNKIT_G(superglobals)) {
ALLOC_HASHTABLE(RUNKIT_G(superglobals));
Expand Down
Loading

0 comments on commit acdbb2f

Please sign in to comment.