From 64f71c1a49470793a54888511d88e5592614728e Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 7 Mar 2021 18:15:44 +0000 Subject: [PATCH 1/7] #2111 - Add reflection tests cases --- ext/config.m4 | 1 + ext/config.w32 | 2 +- ext/stub.c | 2 ++ ext/stub.h | 1 + ext/stub/requires.zep.c | 2 +- ext/stub/requires/external3.zep.c | 4 ++-- ext/stub/resourcetest.zep.c | 2 +- ext/stub/router.zep.c | 6 +++--- ext/stub/scall.zep.c | 8 ++++---- ext/stub/scope.zep.c | 4 ++-- ext/stub/sort.zep.c | 6 +++--- ext/stub/spectralnorm.zep.c | 32 +++++++++++++++--------------- ext/stub/strings.zep.c | 6 +++--- ext/stub/trytest.zep.c | 12 +++++------ stub/reflection.zep | 18 +++++++++++++++++ tests/Extension/ReflectionTest.php | 30 ++++++++++++++++++++++++++++ 16 files changed, 94 insertions(+), 42 deletions(-) create mode 100644 stub/reflection.zep create mode 100644 tests/Extension/ReflectionTest.php diff --git a/ext/config.m4 b/ext/config.m4 index 7f8438210c..5e818b3185 100644 --- a/ext/config.m4 +++ b/ext/config.m4 @@ -171,6 +171,7 @@ if test "$PHP_STUB" = "yes"; then stub/quantum.zep.c stub/range.zep.c stub/references.zep.c + stub/reflection.zep.c stub/regexdna.zep.c stub/requires.zep.c stub/requires/external3.zep.c diff --git a/ext/config.w32 b/ext/config.w32 index f2b20df504..588cb5f7a6 100644 --- a/ext/config.w32 +++ b/ext/config.w32 @@ -11,7 +11,7 @@ if (PHP_STUB != "no") { } ADD_SOURCES(configure_module_dirname + "/stub/invokes", "abstractprotected.zep.c abstractinvoker.zep.c abstractinvokercomplex.zep.c invokeprotected.zep.c invokeprotectedcomplex.zep.c", "stub"); - ADD_SOURCES(configure_module_dirname + "/stub", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayaccessobj.zep.c arrayaccesstest.zep.c arrayiterator.zep.c arrayiteratortest.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c functions.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1404.zep.c issue1521.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scalllateconstruct.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c 10__closure.zep.c 11__closure.zep.c 12__closure.zep.c", "stub"); + ADD_SOURCES(configure_module_dirname + "/stub", "testinterface.zep.c scallparent.zep.c constantsparent.zep.c methodinterface.zep.c arithmetic.zep.c arrayaccessobj.zep.c arrayaccesstest.zep.c arrayiterator.zep.c arrayiteratortest.zep.c arrayobject.zep.c arraysearch.zep.c assign.zep.c bitwise.zep.c branchprediction.zep.c cast.zep.c cblock.zep.c chars.zep.c closures.zep.c compare.zep.c concat.zep.c constants.zep.c constantsinterface.zep.c constantsinterfacea.zep.c constantsinterfaceb.zep.c declaretest.zep.c diinterface.zep.c echoes.zep.c emptytest.zep.c evaltest.zep.c exception.zep.c exceptions.zep.c exists.zep.c exitdie.zep.c extendedinterface.zep.c factorial.zep.c fannkuch.zep.c fasta.zep.c fcall.zep.c fetchtest.zep.c fibonnaci.zep.c flow.zep.c fortytwo.zep.c functional.zep.c functionexists.zep.c functions.zep.c geometry.zep.c globals.zep.c instance.zep.c instanceoff.zep.c internalclasses.zep.c internalinterfaces.zep.c invoke.zep.c issettest.zep.c issue1404.zep.c issue1521.zep.c issues.zep.c json.zep.c logical.zep.c mcall.zep.c mcallchained.zep.c mcalldynamic.zep.c mcallinternal.zep.c methodabstract.zep.c methodargs.zep.c nativearray.zep.c oo.zep.c operator.zep.c pdostatement.zep.c pregmatch.zep.c quantum.zep.c range.zep.c references.zep.c reflection.zep.c regexdna.zep.c requires.zep.c resourcetest.zep.c returns.zep.c router.zep.c scall.zep.c scalldynamic.zep.c scallexternal.zep.c scalllateconstruct.zep.c scope.zep.c sort.zep.c spectralnorm.zep.c spropertyaccess.zep.c statements.zep.c strings.zep.c stubs.zep.c ternary.zep.c trytest.zep.c typeinstances.zep.c typeoff.zep.c unknownclass.zep.c unsettest.zep.c usetest.zep.c vars.zep.c 0__closure.zep.c 1__closure.zep.c 2__closure.zep.c 3__closure.zep.c 4__closure.zep.c 5__closure.zep.c 6__closure.zep.c 7__closure.zep.c 8__closure.zep.c 9__closure.zep.c 10__closure.zep.c 11__closure.zep.c 12__closure.zep.c", "stub"); ADD_SOURCES(configure_module_dirname + "/stub/oo/extend", "exception.zep.c", "stub"); ADD_SOURCES(configure_module_dirname + "/stub/oo/extend/db", "exception.zep.c", "stub"); ADD_SOURCES(configure_module_dirname + "/stub/globals/session", "base.zep.c child.zep.c", "stub"); diff --git a/ext/stub.c b/ext/stub.c index c2a4f8402d..1631571d12 100644 --- a/ext/stub.c +++ b/ext/stub.c @@ -198,6 +198,7 @@ zend_class_entry *stub_properties_staticpublicproperties_ce; zend_class_entry *stub_quantum_ce; zend_class_entry *stub_range_ce; zend_class_entry *stub_references_ce; +zend_class_entry *stub_reflection_ce; zend_class_entry *stub_regexdna_ce; zend_class_entry *stub_requires_ce; zend_class_entry *stub_requires_external3_ce; @@ -406,6 +407,7 @@ static PHP_MINIT_FUNCTION(stub) ZEPHIR_INIT(Stub_Quantum); ZEPHIR_INIT(Stub_Range); ZEPHIR_INIT(Stub_References); + ZEPHIR_INIT(Stub_Reflection); ZEPHIR_INIT(Stub_RegexDNA); ZEPHIR_INIT(Stub_Requires); ZEPHIR_INIT(Stub_Requires_External3); diff --git a/ext/stub.h b/ext/stub.h index 8aee4b1e3b..eab71011ad 100644 --- a/ext/stub.h +++ b/ext/stub.h @@ -166,6 +166,7 @@ #include "stub/quantum.zep.h" #include "stub/range.zep.h" #include "stub/references.zep.h" +#include "stub/reflection.zep.h" #include "stub/regexdna.zep.h" #include "stub/requires.zep.h" #include "stub/requires/external3.zep.h" diff --git a/ext/stub/requires.zep.c b/ext/stub/requires.zep.c index 3481aabf5f..c6a3bd856f 100644 --- a/ext/stub/requires.zep.c +++ b/ext/stub/requires.zep.c @@ -120,7 +120,7 @@ PHP_METHOD(Stub_Requires, requireExternal3) { ZEPHIR_CALL_METHOD(NULL, &external3, "__construct", NULL, 0); zephir_check_call_status(); } - ZEPHIR_CALL_METHOD(NULL, &external3, "req", NULL, 79, path, this_ptr); + ZEPHIR_CALL_METHOD(NULL, &external3, "req", NULL, 81, path, this_ptr); zephir_check_call_status(); RETURN_MM_MEMBER(getThis(), "content"); diff --git a/ext/stub/requires/external3.zep.c b/ext/stub/requires/external3.zep.c index 499290e16e..8357223614 100644 --- a/ext/stub/requires/external3.zep.c +++ b/ext/stub/requires/external3.zep.c @@ -56,12 +56,12 @@ PHP_METHOD(Stub_Requires_External3, req) { - ZEPHIR_CALL_FUNCTION(NULL, "ob_clean", NULL, 80); + ZEPHIR_CALL_FUNCTION(NULL, "ob_clean", NULL, 82); zephir_check_call_status(); if (zephir_require_zval(path) == FAILURE) { RETURN_MM_NULL(); } - ZEPHIR_CALL_FUNCTION(&_0, "ob_get_contents", NULL, 81); + ZEPHIR_CALL_FUNCTION(&_0, "ob_get_contents", NULL, 83); zephir_check_call_status(); ZEPHIR_CALL_METHOD(NULL, requires, "setcontent", NULL, 0, &_0); zephir_check_call_status(); diff --git a/ext/stub/resourcetest.zep.c b/ext/stub/resourcetest.zep.c index f3cce89d32..c7ceb30ea4 100644 --- a/ext/stub/resourcetest.zep.c +++ b/ext/stub/resourcetest.zep.c @@ -129,7 +129,7 @@ PHP_METHOD(Stub_ResourceTest, testFunctionsForSTDIN) { ZEPHIR_INIT_VAR(&a); ZEPHIR_GET_CONSTANT(&a, "STDIN"); ZVAL_LONG(&_0, 1); - ZEPHIR_CALL_FUNCTION(NULL, "stream_set_blocking", NULL, 82, &a, &_0); + ZEPHIR_CALL_FUNCTION(NULL, "stream_set_blocking", NULL, 84, &a, &_0); zephir_check_call_status(); ZEPHIR_MM_RESTORE(); diff --git a/ext/stub/router.zep.c b/ext/stub/router.zep.c index c2fc2f7f91..45d4c806ef 100644 --- a/ext/stub/router.zep.c +++ b/ext/stub/router.zep.c @@ -148,7 +148,7 @@ PHP_METHOD(Stub_Router, __construct) { add_assoc_long_ex(&_1$$3, SL("controller"), 1); ZEPHIR_INIT_VAR(&_2$$3); ZVAL_STRING(&_2$$3, "#^/([a-zA-Z0-9\\_\\-]+)[/]{0,1}$#"); - ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", &_3, 83, &_2$$3, &_1$$3); + ZEPHIR_CALL_METHOD(NULL, &_0$$3, "__construct", &_3, 85, &_2$$3, &_1$$3); zephir_check_call_status(); zephir_array_append(&routes, &_0$$3, PH_SEPARATE, "stub/router.zep", 89); ZEPHIR_INIT_NVAR(&_2$$3); @@ -160,7 +160,7 @@ PHP_METHOD(Stub_Router, __construct) { add_assoc_long_ex(&_4$$3, SL("params"), 3); ZEPHIR_INIT_VAR(&_5$$3); ZVAL_STRING(&_5$$3, "#^/([a-zA-Z0-9\\_\\-]+)/([a-zA-Z0-9\\.\\_]+)(/.*)*$#"); - ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", &_3, 83, &_5$$3, &_4$$3); + ZEPHIR_CALL_METHOD(NULL, &_2$$3, "__construct", &_3, 85, &_5$$3, &_4$$3); zephir_check_call_status(); zephir_array_append(&routes, &_2$$3, PH_SEPARATE, "stub/router.zep", 95); } @@ -1139,7 +1139,7 @@ PHP_METHOD(Stub_Router, add) { ZEPHIR_INIT_VAR(&route); object_init_ex(&route, stub_router_route_ce); - ZEPHIR_CALL_METHOD(NULL, &route, "__construct", NULL, 83, pattern, paths, httpMethods); + ZEPHIR_CALL_METHOD(NULL, &route, "__construct", NULL, 85, pattern, paths, httpMethods); zephir_check_call_status(); zephir_update_property_array_append(this_ptr, SL("_routes"), &route); RETURN_CCTOR(&route); diff --git a/ext/stub/scall.zep.c b/ext/stub/scall.zep.c index 2c5357c4dc..683eab5423 100644 --- a/ext/stub/scall.zep.c +++ b/ext/stub/scall.zep.c @@ -191,7 +191,7 @@ PHP_METHOD(Stub_Scall, testCall3) { ZEPHIR_MM_GROW(); - ZEPHIR_RETURN_CALL_SELF("testmethod3", &_0, 84); + ZEPHIR_RETURN_CALL_SELF("testmethod3", &_0, 86); zephir_check_call_status(); RETURN_MM(); @@ -282,7 +282,7 @@ PHP_METHOD(Stub_Scall, testCall6) { - ZEPHIR_RETURN_CALL_SELF("testmethod6", &_0, 85, a, b); + ZEPHIR_RETURN_CALL_SELF("testmethod6", &_0, 87, a, b); zephir_check_call_status(); RETURN_MM(); @@ -331,7 +331,7 @@ PHP_METHOD(Stub_Scall, testCall9) { ZEPHIR_MM_GROW(); - ZEPHIR_RETURN_CALL_SELF("testmethod3", &_0, 84); + ZEPHIR_RETURN_CALL_SELF("testmethod3", &_0, 86); zephir_check_call_status(); RETURN_MM(); @@ -422,7 +422,7 @@ PHP_METHOD(Stub_Scall, testCall12) { - ZEPHIR_RETURN_CALL_SELF("testmethod6", &_0, 85, a, b); + ZEPHIR_RETURN_CALL_SELF("testmethod6", &_0, 87, a, b); zephir_check_call_status(); RETURN_MM(); diff --git a/ext/stub/scope.zep.c b/ext/stub/scope.zep.c index fbf95a7cbf..e95099d367 100644 --- a/ext/stub/scope.zep.c +++ b/ext/stub/scope.zep.c @@ -85,7 +85,7 @@ PHP_METHOD(Stub_Scope, test1) { ZEPHIR_INIT_VAR(&ret); ZVAL_STRING(&ret, ""); - ZEPHIR_CALL_SELF(&k, "getstr", &_0, 86); + ZEPHIR_CALL_SELF(&k, "getstr", &_0, 88); zephir_check_call_status(); r = 1; if (r == 1) { @@ -183,7 +183,7 @@ PHP_METHOD(Stub_Scope, test3) { } ZEPHIR_INIT_NVAR(&c); ZVAL_LONG(&c, _1); - ZEPHIR_CALL_SELF(&str$$3, "getdystr", &_3, 87, &c); + ZEPHIR_CALL_SELF(&str$$3, "getdystr", &_3, 89, &c); zephir_check_call_status(); zephir_concat_self(&k, &str$$3); } diff --git a/ext/stub/sort.zep.c b/ext/stub/sort.zep.c index 4263503dd1..34c6ce61a3 100644 --- a/ext/stub/sort.zep.c +++ b/ext/stub/sort.zep.c @@ -102,16 +102,16 @@ PHP_METHOD(Stub_Sort, quick) { } } } - ZEPHIR_CALL_METHOD(&_7, this_ptr, "quick", &_8, 88, &left); + ZEPHIR_CALL_METHOD(&_7, this_ptr, "quick", &_8, 90, &left); zephir_check_call_status(); ZEPHIR_INIT_VAR(&_9); zephir_create_array(&_9, 1, 0); ZEPHIR_INIT_VAR(&_10); ZVAL_LONG(&_10, pivot); zephir_array_fast_append(&_9, &_10); - ZEPHIR_CALL_METHOD(&_11, this_ptr, "quick", &_8, 88, &right); + ZEPHIR_CALL_METHOD(&_11, this_ptr, "quick", &_8, 90, &right); zephir_check_call_status(); - ZEPHIR_RETURN_CALL_FUNCTION("array_merge", NULL, 89, &_7, &_9, &_11); + ZEPHIR_RETURN_CALL_FUNCTION("array_merge", NULL, 91, &_7, &_9, &_11); zephir_check_call_status(); RETURN_MM(); diff --git a/ext/stub/spectralnorm.zep.c b/ext/stub/spectralnorm.zep.c index 0cd92ef46b..222a2d6a2c 100644 --- a/ext/stub/spectralnorm.zep.c +++ b/ext/stub/spectralnorm.zep.c @@ -132,7 +132,7 @@ PHP_METHOD(Stub_SpectralNorm, Au) { j = _4$$3; ZVAL_LONG(&_7$$4, i); ZVAL_LONG(&_8$$4, j); - ZEPHIR_CALL_METHOD(&_6$$4, this_ptr, "ax", &_9, 90, &_7$$4, &_8$$4); + ZEPHIR_CALL_METHOD(&_6$$4, this_ptr, "ax", &_9, 92, &_7$$4, &_8$$4); zephir_check_call_status(); ZVAL_LONG(&_7$$4, j); ZEPHIR_CALL_METHOD(&_10$$4, u, "offsetget", &_11, 0, &_7$$4); @@ -218,7 +218,7 @@ PHP_METHOD(Stub_SpectralNorm, Atu) { j = _4$$3; ZVAL_LONG(&_7$$4, j); ZVAL_LONG(&_8$$4, i); - ZEPHIR_CALL_METHOD(&_6$$4, this_ptr, "ax", &_9, 90, &_7$$4, &_8$$4); + ZEPHIR_CALL_METHOD(&_6$$4, this_ptr, "ax", &_9, 92, &_7$$4, &_8$$4); zephir_check_call_status(); ZVAL_LONG(&_7$$4, j); ZEPHIR_CALL_METHOD(&_10$$4, u, "offsetget", &_11, 0, &_7$$4); @@ -266,9 +266,9 @@ PHP_METHOD(Stub_SpectralNorm, AtAu) { - ZEPHIR_CALL_METHOD(NULL, this_ptr, "au", NULL, 91, n, u, w); + ZEPHIR_CALL_METHOD(NULL, this_ptr, "au", NULL, 93, n, u, w); zephir_check_call_status(); - ZEPHIR_CALL_METHOD(NULL, this_ptr, "atu", NULL, 92, n, w, v); + ZEPHIR_CALL_METHOD(NULL, this_ptr, "atu", NULL, 94, n, w, v); zephir_check_call_status(); ZEPHIR_MM_RESTORE(); @@ -315,17 +315,17 @@ PHP_METHOD(Stub_SpectralNorm, process) { ZEPHIR_INIT_VAR(&u); object_init_ex(&u, spl_ce_SplFixedArray); ZVAL_LONG(&_0, n); - ZEPHIR_CALL_METHOD(NULL, &u, "__construct", NULL, 93, &_0); + ZEPHIR_CALL_METHOD(NULL, &u, "__construct", NULL, 95, &_0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&v); object_init_ex(&v, spl_ce_SplFixedArray); ZVAL_LONG(&_0, n); - ZEPHIR_CALL_METHOD(NULL, &v, "__construct", NULL, 93, &_0); + ZEPHIR_CALL_METHOD(NULL, &v, "__construct", NULL, 95, &_0); zephir_check_call_status(); ZEPHIR_INIT_VAR(&w); object_init_ex(&w, spl_ce_SplFixedArray); ZVAL_LONG(&_0, n); - ZEPHIR_CALL_METHOD(NULL, &w, "__construct", NULL, 93, &_0); + ZEPHIR_CALL_METHOD(NULL, &w, "__construct", NULL, 95, &_0); zephir_check_call_status(); _3 = (n - 1); _2 = 0; @@ -343,15 +343,15 @@ PHP_METHOD(Stub_SpectralNorm, process) { i = _2; ZVAL_LONG(&_4$$3, i); ZVAL_LONG(&_5$$3, 1); - ZEPHIR_CALL_METHOD(NULL, &u, "offsetset", &_6, 94, &_4$$3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &u, "offsetset", &_6, 96, &_4$$3, &_5$$3); zephir_check_call_status(); ZVAL_LONG(&_4$$3, i); ZVAL_LONG(&_5$$3, 1); - ZEPHIR_CALL_METHOD(NULL, &v, "offsetset", &_6, 94, &_4$$3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &v, "offsetset", &_6, 96, &_4$$3, &_5$$3); zephir_check_call_status(); ZVAL_LONG(&_4$$3, i); ZVAL_LONG(&_5$$3, 1); - ZEPHIR_CALL_METHOD(NULL, &w, "offsetset", &_6, 94, &_4$$3, &_5$$3); + ZEPHIR_CALL_METHOD(NULL, &w, "offsetset", &_6, 96, &_4$$3, &_5$$3); zephir_check_call_status(); } } @@ -370,10 +370,10 @@ PHP_METHOD(Stub_SpectralNorm, process) { } i = _8; ZVAL_LONG(&_10$$4, n); - ZEPHIR_CALL_METHOD(NULL, this_ptr, "atau", &_11, 95, &_10$$4, &u, &v, &w); + ZEPHIR_CALL_METHOD(NULL, this_ptr, "atau", &_11, 97, &_10$$4, &u, &v, &w); zephir_check_call_status(); ZVAL_LONG(&_10$$4, n); - ZEPHIR_CALL_METHOD(NULL, this_ptr, "atau", &_11, 95, &_10$$4, &v, &u, &w); + ZEPHIR_CALL_METHOD(NULL, this_ptr, "atau", &_11, 97, &_10$$4, &v, &u, &w); zephir_check_call_status(); } } @@ -392,19 +392,19 @@ PHP_METHOD(Stub_SpectralNorm, process) { } i = _13; ZVAL_LONG(&_16$$5, i); - ZEPHIR_CALL_METHOD(&_15$$5, &u, "offsetget", &_17, 96, &_16$$5); + ZEPHIR_CALL_METHOD(&_15$$5, &u, "offsetget", &_17, 98, &_16$$5); zephir_check_call_status(); ZVAL_LONG(&_16$$5, i); - ZEPHIR_CALL_METHOD(&_18$$5, &v, "offsetget", &_17, 96, &_16$$5); + ZEPHIR_CALL_METHOD(&_18$$5, &v, "offsetget", &_17, 98, &_16$$5); zephir_check_call_status(); ZEPHIR_INIT_NVAR(&_19$$5); mul_function(&_19$$5, &_15$$5, &_18$$5); vBv += zephir_get_numberval(&_19$$5); ZVAL_LONG(&_16$$5, i); - ZEPHIR_CALL_METHOD(&_15$$5, &v, "offsetget", &_17, 96, &_16$$5); + ZEPHIR_CALL_METHOD(&_15$$5, &v, "offsetget", &_17, 98, &_16$$5); zephir_check_call_status(); ZVAL_LONG(&_16$$5, i); - ZEPHIR_CALL_METHOD(&_18$$5, &v, "offsetget", &_17, 96, &_16$$5); + ZEPHIR_CALL_METHOD(&_18$$5, &v, "offsetget", &_17, 98, &_16$$5); zephir_check_call_status(); ZEPHIR_INIT_NVAR(&_20$$5); mul_function(&_20$$5, &_15$$5, &_18$$5); diff --git a/ext/stub/strings.zep.c b/ext/stub/strings.zep.c index 41125e2456..77c8eeb152 100644 --- a/ext/stub/strings.zep.c +++ b/ext/stub/strings.zep.c @@ -752,7 +752,7 @@ PHP_METHOD(Stub_Strings, strToHex) { _1$$3 = ZEPHIR_STRING_OFFSET(&value, i); ZEPHIR_INIT_NVAR(&_2$$3); ZVAL_STRINGL(&_2$$3, &_1$$3, 1); - ZEPHIR_CALL_FUNCTION(&_3$$3, "ord", &_4, 97, &_2$$3); + ZEPHIR_CALL_FUNCTION(&_3$$3, "ord", &_4, 99, &_2$$3); zephir_check_call_status(); ZEPHIR_CALL_FUNCTION(&_5$$3, "dechex", &_6, 10, &_3$$3); zephir_check_call_status(); @@ -817,13 +817,13 @@ PHP_METHOD(Stub_Strings, issue1267) { zephir_check_call_status(); ZEPHIR_CPY_WRT(value, &_4); ZEPHIR_INIT_NVAR(&_0); - ZEPHIR_CALL_FUNCTION(&_4, "strip_tags", &_5, 98, value); + ZEPHIR_CALL_FUNCTION(&_4, "strip_tags", &_5, 100, value); zephir_check_call_status(); zephir_stripslashes(&_0, &_4); ZEPHIR_INIT_VAR(&x); zephir_fast_trim(&x, &_0, NULL , ZEPHIR_TRIM_BOTH); ZEPHIR_INIT_VAR(&_6); - ZEPHIR_CALL_FUNCTION(&_7, "strip_tags", &_5, 98, value); + ZEPHIR_CALL_FUNCTION(&_7, "strip_tags", &_5, 100, value); zephir_check_call_status(); zephir_stripcslashes(&_6, &_7); zephir_fast_trim(return_value, &_6, NULL , ZEPHIR_TRIM_BOTH); diff --git a/ext/stub/trytest.zep.c b/ext/stub/trytest.zep.c index 1268bb5540..7a147cec2c 100644 --- a/ext/stub/trytest.zep.c +++ b/ext/stub/trytest.zep.c @@ -205,7 +205,7 @@ PHP_METHOD(Stub_TryTest, testTry4) { object_init_ex(&_2$$5, spl_ce_RuntimeException); ZEPHIR_INIT_VAR(&_3$$5); ZVAL_STRING(&_3$$5, "error!"); - ZEPHIR_CALL_METHOD(NULL, &_2$$5, "__construct", NULL, 99, &_3$$5); + ZEPHIR_CALL_METHOD(NULL, &_2$$5, "__construct", NULL, 101, &_3$$5); zephir_check_call_status_or_jump(try_end_1); zephir_throw_exception_debug(&_2$$5, "stub/trytest.zep", 48); goto try_end_1; @@ -283,7 +283,7 @@ PHP_METHOD(Stub_TryTest, testTry5) { object_init_ex(&_2$$5, spl_ce_RuntimeException); ZEPHIR_INIT_VAR(&_3$$5); ZVAL_STRING(&_3$$5, "error!"); - ZEPHIR_CALL_METHOD(NULL, &_2$$5, "__construct", NULL, 99, &_3$$5); + ZEPHIR_CALL_METHOD(NULL, &_2$$5, "__construct", NULL, 101, &_3$$5); zephir_check_call_status_or_jump(try_end_1); zephir_throw_exception_debug(&_2$$5, "stub/trytest.zep", 65); goto try_end_1; @@ -360,7 +360,7 @@ PHP_METHOD(Stub_TryTest, testTry6) { object_init_ex(&_2$$5, spl_ce_RuntimeException); ZEPHIR_INIT_VAR(&_3$$5); ZVAL_STRING(&_3$$5, "error!"); - ZEPHIR_CALL_METHOD(NULL, &_2$$5, "__construct", NULL, 99, &_3$$5); + ZEPHIR_CALL_METHOD(NULL, &_2$$5, "__construct", NULL, 101, &_3$$5); zephir_check_call_status_or_jump(try_end_1); zephir_throw_exception_debug(&_2$$5, "stub/trytest.zep", 82); goto try_end_1; @@ -436,7 +436,7 @@ PHP_METHOD(Stub_TryTest, testTry7) { object_init_ex(&_2$$5, spl_ce_RuntimeException); ZEPHIR_INIT_VAR(&_3$$5); ZVAL_STRING(&_3$$5, "error!"); - ZEPHIR_CALL_METHOD(NULL, &_2$$5, "__construct", NULL, 99, &_3$$5); + ZEPHIR_CALL_METHOD(NULL, &_2$$5, "__construct", NULL, 101, &_3$$5); zephir_check_call_status_or_jump(try_end_1); zephir_throw_exception_debug(&_2$$5, "stub/trytest.zep", 101); goto try_end_1; @@ -536,7 +536,7 @@ PHP_METHOD(Stub_TryTest, testTry9) { /* try_start_1: */ - ZEPHIR_CALL_METHOD(NULL, this_ptr, "somemethod1", NULL, 100); + ZEPHIR_CALL_METHOD(NULL, this_ptr, "somemethod1", NULL, 102); zephir_check_call_status_or_jump(try_end_1); RETURN_MM_STRING("not catched"); @@ -572,7 +572,7 @@ PHP_METHOD(Stub_TryTest, testTry10) { /* try_start_1: */ - ZEPHIR_CALL_METHOD(NULL, this_ptr, "somemethod2", NULL, 101); + ZEPHIR_CALL_METHOD(NULL, this_ptr, "somemethod2", NULL, 103); zephir_check_call_status_or_jump(try_end_1); RETURN_MM_STRING("not catched"); diff --git a/stub/reflection.zep b/stub/reflection.zep new file mode 100644 index 0000000000..bdf36f88ae --- /dev/null +++ b/stub/reflection.zep @@ -0,0 +1,18 @@ + +namespace Stub; + +use ReflectionClass; +use ReflectionFunction; + +class Reflection +{ + public function getReflectionClass() -> + { + return new ReflectionClass(); + } + + public function getReflectionFunction() -> + { + return new ReflectionFunction(); + } +} diff --git a/tests/Extension/ReflectionTest.php b/tests/Extension/ReflectionTest.php new file mode 100644 index 0000000000..54ae36343e --- /dev/null +++ b/tests/Extension/ReflectionTest.php @@ -0,0 +1,30 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +namespace Extension; + +use PHPUnit\Framework\TestCase; +use ReflectionClass; +use ReflectionFunction; +use Stub\Reflection as StubReflection; + +final class ReflectionTest extends TestCase +{ + public function testMethods(): void + { + $class = new StubReflection(); + + $this->assertInstanceOf(ReflectionClass::class, $class->getReflectionClass()); + $this->assertInstanceOf(ReflectionFunction::class, $class->getReflectionFunction()); + } +} From ee43627ddd3ace85f9de08ba1f2ed9ff9cccd9f8 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 7 Mar 2021 18:29:37 +0000 Subject: [PATCH 2/7] #2111 - Adjust reflection classes declaration --- stub/reflection.zep | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/stub/reflection.zep b/stub/reflection.zep index bdf36f88ae..5257d9ce04 100644 --- a/stub/reflection.zep +++ b/stub/reflection.zep @@ -8,11 +8,17 @@ class Reflection { public function getReflectionClass() -> { - return new ReflectionClass(); + var r; + let r = new ReflectionClass(); + + return r; } public function getReflectionFunction() -> { - return new ReflectionFunction(); + var r; + let r = new ReflectionFunction(); + + return r; } } From fb4e01a633fad314c44b3015dbdd50424f06e84c Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 7 Mar 2021 18:43:56 +0000 Subject: [PATCH 3/7] #2111 - Disable adding header --- Library/ClassDefinition.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index 210a791bfe..47c537cfb2 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1850,7 +1850,7 @@ public function getClassEntryByClassName($className, CompilationContext $compila $classEntry = 'reflection_function_abstract_ptr'; break; case 'reflectionfunction': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); + //$compilationContext->headersManager->add('ext/reflection/php_reflection'); $classEntry = 'reflection_function_ptr'; break; case 'reflectionparameter': @@ -1858,7 +1858,7 @@ public function getClassEntryByClassName($className, CompilationContext $compila $classEntry = 'reflection_parameter_ptr'; break; case 'reflectionclass': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); + //$compilationContext->headersManager->add('ext/reflection/php_reflection'); $classEntry = 'reflection_class_ptr'; break; case 'reflectionobject': From 6395c6e736b02152b29737d14d052d5565bccd59 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 7 Mar 2021 19:10:30 +0000 Subject: [PATCH 4/7] #2111 - Add test cases for Reflection --- stub/reflection.zep | 19 +++++++++++++++++-- tests/Extension/ReflectionTest.php | 8 ++++++++ 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/stub/reflection.zep b/stub/reflection.zep index 5257d9ce04..f8be13a4a6 100644 --- a/stub/reflection.zep +++ b/stub/reflection.zep @@ -3,13 +3,16 @@ namespace Stub; use ReflectionClass; use ReflectionFunction; +use ReflectionParameter; class Reflection { + private reflectionParameter = null; + public function getReflectionClass() -> { var r; - let r = new ReflectionClass(); + let r = new ReflectionClass(this); return r; } @@ -17,8 +20,20 @@ class Reflection public function getReflectionFunction() -> { var r; - let r = new ReflectionFunction(); + let r = new ReflectionFunction("abs"); return r; } + + public function setReflectionParameter( parameter) -> + { + let this->reflectionParameter = parameter; + + return this->reflectionParameter; + } + + public function getReflectionParameter() -> | null + { + return this->reflectionParameter; + } } diff --git a/tests/Extension/ReflectionTest.php b/tests/Extension/ReflectionTest.php index 54ae36343e..15da5ed41e 100644 --- a/tests/Extension/ReflectionTest.php +++ b/tests/Extension/ReflectionTest.php @@ -16,6 +16,7 @@ use PHPUnit\Framework\TestCase; use ReflectionClass; use ReflectionFunction; +use ReflectionParameter; use Stub\Reflection as StubReflection; final class ReflectionTest extends TestCase @@ -26,5 +27,12 @@ public function testMethods(): void $this->assertInstanceOf(ReflectionClass::class, $class->getReflectionClass()); $this->assertInstanceOf(ReflectionFunction::class, $class->getReflectionFunction()); + $this->assertNull($class->getReflectionParameter()); + + $class->setReflectionParameter(new ReflectionParameter(function ($test) { + return 1; + }, 0)); + + $this->assertInstanceOf(ReflectionParameter::class, $class->getReflectionParameter()); } } From 8aa058dc8f88e9dc24189da23403c7c718bd4ed1 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 7 Mar 2021 19:19:58 +0000 Subject: [PATCH 5/7] #2111 - Separate reflection class entry detection for PHP8 only --- Library/ClassDefinition.php | 122 +++++++++++++++++++++--------------- 1 file changed, 70 insertions(+), 52 deletions(-) diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index 47c537cfb2..d022b9e78c 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1447,10 +1447,78 @@ public function setAliasManager(AliasManager $aliasManager) * * @return string */ - public function getClassEntryByClassName($className, CompilationContext $compilationContext, $check = true) - { + public function getClassEntryByClassName( + string $className, + CompilationContext $compilationContext, + bool $check = true + ): string { $this->compiler = $compilationContext->compiler; + /** + * Special treatment for Reflection in 8.0. + * Because in PHP 7.4 param arg info is lighter, + * but also incomplete. + */ + if (version_compare(PHP_VERSION, '8.0.0', '>=')) { + switch (strtolower($className)) { + case 'reflector': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflector_ptr'; + break; + case 'reflectionexception': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_exception_ptr'; + break; + case 'reflection': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_ptr'; + break; + case 'reflectionfunctionabstract': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_function_abstract_ptr'; + break; + case 'reflectionfunction': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_function_ptr'; + break; + case 'reflectionparameter': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_parameter_ptr'; + break; + case 'reflectionclass': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_class_ptr'; + break; + case 'reflectionobject': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_object_ptr'; + break; + case 'reflectionmethod': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_method_ptr'; + break; + case 'reflectionproperty': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_property_ptr'; + break; + case 'reflectionextension': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_extension_ptr'; + break; + case 'reflectionzendextension': + $compilationContext->headersManager->add('ext/reflection/php_reflection'); + $classEntry = 'reflection_zend_extension_ptr'; + break; + default: + $classEntry = null; + break; + } + + if ($classEntry !== null) { + return $classEntry; + } + } + switch (strtolower($className)) { /** * Zend exceptions @@ -1832,56 +1900,6 @@ public function getClassEntryByClassName($className, CompilationContext $compila $classEntry = 'php_session_iface_entry'; break; - // Reflection - case 'reflector': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflector_ptr'; - break; - case 'reflectionexception': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_exception_ptr'; - break; - case 'reflection': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_ptr'; - break; - case 'reflectionfunctionabstract': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_function_abstract_ptr'; - break; - case 'reflectionfunction': - //$compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_function_ptr'; - break; - case 'reflectionparameter': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_parameter_ptr'; - break; - case 'reflectionclass': - //$compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_class_ptr'; - break; - case 'reflectionobject': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_object_ptr'; - break; - case 'reflectionmethod': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_method_ptr'; - break; - case 'reflectionproperty': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_property_ptr'; - break; - case 'reflectionextension': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_extension_ptr'; - break; - case 'reflectionzendextension': - $compilationContext->headersManager->add('ext/reflection/php_reflection'); - $classEntry = 'reflection_zend_extension_ptr'; - break; - default: if (!$check) { throw new CompilerException('Unknown class entry for "'.$className.'"'); From 6c3bc50cc5ae834231993430bb55388f1dcd883e Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 7 Mar 2021 19:29:39 +0000 Subject: [PATCH 6/7] #2111 - Change command for "Compile Stub Porject" step --- .github/workflows/build-unix.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build-unix.yml b/.github/workflows/build-unix.yml index cefa521f06..1c358e03d8 100644 --- a/.github/workflows/build-unix.yml +++ b/.github/workflows/build-unix.yml @@ -165,7 +165,7 @@ jobs: CXXFLAGS="-O0 -ggdb -fprofile-arcs -ftest-coverage" # Export variables in the subshell to not shadow global variables - ( export LDFLAGS CFLAGS CXXFLAGS; zephir compile ) || false + ( export LDFLAGS CFLAGS CXXFLAGS; zephir fullclean && zephir generate && cd ext/ && ./install ) || false - name: Setup Problem Matchers for PHPUnit run: echo ::add-matcher::${{ runner.tool_cache }}/phpunit.json From 5bd5677e29f9285a03da44bed3bf56fcb338bce6 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 7 Mar 2021 20:32:48 +0000 Subject: [PATCH 7/7] #2111 - Add list of class entries to ignore --- Library/ClassDefinition.php | 6 ++++-- Library/ClassMethod.php | 31 +++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index d022b9e78c..23885c50f5 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1458,8 +1458,10 @@ public function getClassEntryByClassName( * Special treatment for Reflection in 8.0. * Because in PHP 7.4 param arg info is lighter, * but also incomplete. + * + * TODO: Leave for future, maybe PHP code devs will make "reflection" ext public... */ - if (version_compare(PHP_VERSION, '8.0.0', '>=')) { + /*if (version_compare(PHP_VERSION, '8.0.0', '>=')) { switch (strtolower($className)) { case 'reflector': $compilationContext->headersManager->add('ext/reflection/php_reflection'); @@ -1517,7 +1519,7 @@ public function getClassEntryByClassName( if ($classEntry !== null) { return $classEntry; } - } + }*/ switch (strtolower($className)) { /** diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index 84f30610c4..8621c62c72 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -169,6 +169,26 @@ class ClassMethod */ protected $callGathererPass; + /** + * All classes must be in lower case. + * + * @var array|string[] + */ + protected array $excludedClassEntries = [ + 'reflector', + 'reflectionexception', + 'reflection', + 'reflectionfunctionabstract', + 'reflectionfunction', + 'reflectionparameter', + 'reflectionclass', + 'reflectionobject', + 'reflectionmethod', + 'reflectionproperty', + 'reflectionextension', + 'reflectionzendextension', + ]; + /** * ClassMethod constructor. * @@ -2591,6 +2611,17 @@ private function detectClassNameEntry(string $className, CompilationContext $com return null; } + /** + * Excluded classes. + * + * Cases when we can't retrieve class entry. + * For example: php/ext/reflection, as there + * are no PHP_INSTALL_HEADERS. + */ + if (in_array(ltrim(strtolower($className), '\\'), $this->excludedClassEntries)) { + return null; + } + $isAlias = false; $aliasManager = $this->classDefinition->getAliasManager(); if ($aliasManager->isAlias($className)) {