From 32f13b2c0a6ef75029996ae4f8a88a509bf9e6da Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Wed, 12 May 2021 17:23:38 +0100 Subject: [PATCH 01/35] #2245 - Add `Z_PARAM_ZVAL_OR_NULL` for default value --- Library/ClassMethod.php | 6 +++++- stub/mcall.zep | 5 +++++ tests/Extension/MCallTest.php | 7 +++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index 37daaadaa..3153c2e94 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -2334,8 +2334,12 @@ public function detectParam(array $parameter, CompilationContext $compilationCon /** * In case of unknown type, just return generic param type. */ - $param = sprintf('Z_PARAM_ZVAL(%s)', $name); $hasDefaultNull = isset($parameter['default']['type']) && $parameter['default']['type'] === 'null'; + if ($hasDefaultNull) { + $param = sprintf('Z_PARAM_ZVAL_OR_NULL(%s)', $name); + } else { + $param = sprintf('Z_PARAM_ZVAL(%s)', $name); + } switch ($parameter['data-type']) { case 'array': diff --git a/stub/mcall.zep b/stub/mcall.zep index e808f5a38..ad6d55ff5 100644 --- a/stub/mcall.zep +++ b/stub/mcall.zep @@ -278,4 +278,9 @@ class Mcall return _finfo; } + + public function issue2245VarArgumentNullable(var param = null) + { + return param; + } } diff --git a/tests/Extension/MCallTest.php b/tests/Extension/MCallTest.php index 48b41d80d..d2f5a7e16 100644 --- a/tests/Extension/MCallTest.php +++ b/tests/Extension/MCallTest.php @@ -205,4 +205,11 @@ public function testIssue1136(): void $this->assertIsResource($test->issue1136()); } } + + public function testIssue2245DynamicNullableArgMustBeNullableAsDefault(): void + { + $test = new Mcall(); + + $this->assertNull($test->issue2245VarArgumentNullable()); + } } From f819a9426f16de88098b3dca89c5abf461f6fc33 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Wed, 12 May 2021 17:25:45 +0100 Subject: [PATCH 02/35] #2245 - Add changelog --- CHANGELOG.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b445eceb2..10d581552 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,8 @@ The format based on [Keep a Changelog](http://keepachangelog.com) and this project adheres to [Semantic Versioning](http://semver.org). ## [Unreleased] - +### Fixed +- Fixed nullable dynamic argument definition [#2245](https://github.com/zephir-lang/zephir/issues/2245) ## [0.13.5] - 2021-05-09 ### Fixed From 58be1e3ceb6eeb92fae9b8aa14f6662c9d501283 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 27 Jun 2021 23:50:44 +0100 Subject: [PATCH 03/35] #2213 - First attempt to detect all class entries dynamically --- Library/ClassMethod.php | 14 ++++++--- ext/stub/builtin/stringmethods.zep.c | 4 +-- ext/stub/exitdie.zep.c | 4 +-- ext/stub/fcall.zep.c | 2 +- ext/stub/flow.zep.c | 4 +-- ext/stub/instance.zep.c | 23 +++++++------- ext/stub/interfaces/implementinterface.zep.c | 4 +-- ext/stub/issue2165/issue.zep.c | 2 +- ext/stub/mcall.zep.c | 33 ++++++++++++++++++-- ext/stub/mcall.zep.h | 6 ++++ ext/stub/namespaces/classentry.zep.c | 4 +-- ext/stub/oo/ooparams.zep.c | 2 +- ext/stub/reflection.zep.c | 2 +- ext/stub/router.zep.c | 22 ++++++------- ext/stub/router/route.zep.c | 6 ++-- ext/stub/spectralnorm.zep.c | 8 ++--- ext/stub/spropertyaccess.zep.c | 4 +-- ext/stub/strings.zep.c | 4 +-- 18 files changed, 92 insertions(+), 56 deletions(-) diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index 3153c2e94..8c8f8adf5 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -2445,7 +2445,7 @@ private function detectClassNameEntry(string $className, CompilationContext $com * are no PHP_INSTALL_HEADERS. */ if (in_array(ltrim(strtolower($className), '\\'), $this->excludedClassEntries)) { - return null; + //return null; } $isAlias = false; @@ -2461,7 +2461,7 @@ private function detectClassNameEntry(string $className, CompilationContext $com /** * PSR */ - if (strpos($className, 'Psr') === 0 || strpos($className, '\Psr') === 0) { + /*if (strpos($className, 'Psr') === 0 || strpos($className, '\Psr') === 0) { $className = ltrim($className, '\\'); $psrHeaderFiles = [ @@ -2524,7 +2524,7 @@ private function detectClassNameEntry(string $className, CompilationContext $com ); } catch (CompilerException $exception) { // Continue below execution - } + }*/ $classNamespace = explode('\\', $className); @@ -2533,19 +2533,20 @@ private function detectClassNameEntry(string $className, CompilationContext $com */ if (strpos($className, '\\') === 0) { $classNamespace = array_values(array_filter($classNamespace)); + $className = str_replace('\\', '\\\\', $className); /** * External class */ if (count($classNamespace) === 1) { - return null; + return 'zend_lookup_class_ex(zend_string_init_fast(SL("'.$className.'")), NULL, 0)'; } /** * External class, we don't know its ClassEntry in C world. */ if (!preg_match('/^'.$classNamespace[0].'/', $this->classDefinition->getNamespace())) { - return null; + return 'zend_lookup_class_ex(zend_string_init_fast(SL("'.$className.'")), NULL, 0)'; } $className = end($classNamespace); @@ -2564,6 +2565,9 @@ private function detectClassNameEntry(string $className, CompilationContext $com } $namespace = join('\\', $classNamespace); + $namespace = str_replace('\\', '\\\\', $namespace); + + return 'zend_lookup_class_ex(zend_string_init_fast(SL("\\\\'.$namespace.'\\\\'.$className.'")), NULL, 0)'; return (new ClassDefinition($namespace, $className))->getClassEntry(); } diff --git a/ext/stub/builtin/stringmethods.zep.c b/ext/stub/builtin/stringmethods.zep.c index d24556460..d8cd136fa 100644 --- a/ext/stub/builtin/stringmethods.zep.c +++ b/ext/stub/builtin/stringmethods.zep.c @@ -43,7 +43,7 @@ PHP_METHOD(Stub_BuiltIn_StringMethods, camelize) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(delimiter) + Z_PARAM_ZVAL_OR_NULL(delimiter) ZEND_PARSE_PARAMETERS_END(); #endif @@ -78,7 +78,7 @@ PHP_METHOD(Stub_BuiltIn_StringMethods, uncamelize) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(delimiter) + Z_PARAM_ZVAL_OR_NULL(delimiter) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/exitdie.zep.c b/ext/stub/exitdie.zep.c index 5e2c5a091..797c1a8a1 100644 --- a/ext/stub/exitdie.zep.c +++ b/ext/stub/exitdie.zep.c @@ -36,7 +36,7 @@ PHP_METHOD(Stub_ExitDie, testExit) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(param) + Z_PARAM_ZVAL_OR_NULL(param) ZEND_PARSE_PARAMETERS_END(); #endif @@ -65,7 +65,7 @@ PHP_METHOD(Stub_ExitDie, testDie) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(param) + Z_PARAM_ZVAL_OR_NULL(param) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/fcall.zep.c b/ext/stub/fcall.zep.c index 42ebc0121..bd943bfbb 100644 --- a/ext/stub/fcall.zep.c +++ b/ext/stub/fcall.zep.c @@ -239,7 +239,7 @@ PHP_METHOD(Stub_Fcall, zvalFcallWith1Parameter) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(callback) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(param1) + Z_PARAM_ZVAL_OR_NULL(param1) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/flow.zep.c b/ext/stub/flow.zep.c index cc39ee4a7..207a8f906 100644 --- a/ext/stub/flow.zep.c +++ b/ext/stub/flow.zep.c @@ -1929,7 +1929,7 @@ PHP_METHOD(Stub_Flow, testFor33) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(e, zend_ce_iterator) + Z_PARAM_OBJECT_OF_CLASS(e, zend_lookup_class_ex(zend_string_init_fast(SL("\\Iterator")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1967,7 +1967,7 @@ PHP_METHOD(Stub_Flow, testFor34) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_OBJECT_OF_CLASS_OR_NULL(e, zend_ce_iterator) + Z_PARAM_OBJECT_OF_CLASS_OR_NULL(e, zend_lookup_class_ex(zend_string_init_fast(SL("\\Iterator")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/instance.zep.c b/ext/stub/instance.zep.c index ab9430513..6bef3fe40 100644 --- a/ext/stub/instance.zep.c +++ b/ext/stub/instance.zep.c @@ -14,7 +14,6 @@ #include "kernel/main.h" #include "kernel/memory.h" #include "kernel/object.h" -#include "ext/spl/spl_array.h" #include "kernel/array.h" #include "kernel/fcall.h" #include "kernel/operators.h" @@ -49,17 +48,17 @@ PHP_METHOD(Stub_Instance, __construct) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(11, 11) - Z_PARAM_OBJECT_OF_CLASS(a1, stub_arithmetic_ce) - Z_PARAM_OBJECT_OF_CLASS(a2, spl_ce_ArrayObject) - Z_PARAM_OBJECT_OF_CLASS(a3, stub_assign_ce) - Z_PARAM_OBJECT_OF_CLASS(a4, stub_bitwise_ce) - Z_PARAM_OBJECT_OF_CLASS(a5, stub_branchprediction_ce) - Z_PARAM_OBJECT_OF_CLASS(a6, stub_cast_ce) - Z_PARAM_OBJECT_OF_CLASS(a7, stub_cblock_ce) - Z_PARAM_OBJECT_OF_CLASS(a8, stub_chars_ce) - Z_PARAM_OBJECT_OF_CLASS(a9, stub_closures_ce) - Z_PARAM_OBJECT_OF_CLASS(a10, stub_compare_ce) - Z_PARAM_OBJECT_OF_CLASS(a11, stub_concat_ce) + Z_PARAM_OBJECT_OF_CLASS(a1, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Arithmetic")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a2, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\ArrayObject")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a3, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Assign")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a4, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Bitwise")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a5, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\BranchPrediction")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a6, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Cast")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a7, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Cblock")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a8, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Chars")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a9, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Closures")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a10, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Compare")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a11, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Concat")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/interfaces/implementinterface.zep.c b/ext/stub/interfaces/implementinterface.zep.c index a893ad41e..6d499a0dc 100644 --- a/ext/stub/interfaces/implementinterface.zep.c +++ b/ext/stub/interfaces/implementinterface.zep.c @@ -37,7 +37,7 @@ PHP_METHOD(Stub_Interfaces_ImplementInterface, get) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(obj, stub_interfaces_interfaceint_ce) + Z_PARAM_OBJECT_OF_CLASS(obj, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Interfaces\\InterfaceInt")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif @@ -60,7 +60,7 @@ PHP_METHOD(Stub_Interfaces_ImplementInterface, getVoid) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(obj, stub_interfaces_interfaceint_ce) + Z_PARAM_OBJECT_OF_CLASS(obj, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Interfaces\\InterfaceInt")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/issue2165/issue.zep.c b/ext/stub/issue2165/issue.zep.c index 720a3ce3b..bf2420ea3 100644 --- a/ext/stub/issue2165/issue.zep.c +++ b/ext/stub/issue2165/issue.zep.c @@ -559,7 +559,7 @@ PHP_METHOD(Stub_Issue2165_Issue, divideMatrix) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(b, stub_issue2165_issue_ce) + Z_PARAM_OBJECT_OF_CLASS(b, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Issue2165\\Issue")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/mcall.zep.c b/ext/stub/mcall.zep.c index bf2668595..21abe5270 100644 --- a/ext/stub/mcall.zep.c +++ b/ext/stub/mcall.zep.c @@ -828,7 +828,7 @@ PHP_METHOD(Stub_Mcall, optionalParameterVar) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(param) + Z_PARAM_ZVAL_OR_NULL(param) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1051,7 +1051,7 @@ PHP_METHOD(Stub_Mcall, testObjectParamCastStdClass) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(param, zend_standard_class_def) + Z_PARAM_OBJECT_OF_CLASS(param, zend_lookup_class_ex(zend_string_init_fast(SL("\\StdClass")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1072,7 +1072,7 @@ PHP_METHOD(Stub_Mcall, testObjectParamCastOoParam) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(param, stub_oo_param_ce) + Z_PARAM_OBJECT_OF_CLASS(param, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Oo\\Param")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1217,3 +1217,30 @@ PHP_METHOD(Stub_Mcall, issue1136) RETURN_CCTOR(&_finfo); } +PHP_METHOD(Stub_Mcall, issue2245VarArgumentNullable) +{ + zval *param = NULL, param_sub, __$null; + zval *this_ptr = getThis(); + + ZVAL_UNDEF(¶m_sub); + ZVAL_NULL(&__$null); +#if PHP_VERSION_ID >= 80000 + bool is_null_true = 1; + ZEND_PARSE_PARAMETERS_START(0, 1) + Z_PARAM_OPTIONAL + Z_PARAM_ZVAL_OR_NULL(param) + ZEND_PARSE_PARAMETERS_END(); +#endif + + + zephir_fetch_params_without_memory_grow(0, 1, ¶m); + if (!param) { + param = ¶m_sub; + param = &__$null; + } + + + RETVAL_ZVAL(param, 1, 0); + return; +} + diff --git a/ext/stub/mcall.zep.h b/ext/stub/mcall.zep.h index 7b2ab78df..d3a376be1 100644 --- a/ext/stub/mcall.zep.h +++ b/ext/stub/mcall.zep.h @@ -51,6 +51,7 @@ PHP_METHOD(Stub_Mcall, testCallablePass); PHP_METHOD(Stub_Mcall, testCallableArrayThisMethodPass); PHP_METHOD(Stub_Mcall, aa); PHP_METHOD(Stub_Mcall, issue1136); +PHP_METHOD(Stub_Mcall, issue2245VarArgumentNullable); ZEND_BEGIN_ARG_INFO_EX(arginfo_stub_mcall_testmethod1, 0, 0, 0) ZEND_END_ARG_INFO() @@ -254,6 +255,10 @@ ZEND_END_ARG_INFO() ZEND_BEGIN_ARG_INFO_EX(arginfo_stub_mcall_issue1136, 0, 0, 0) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_stub_mcall_issue2245varargumentnullable, 0, 0, 0) + ZEND_ARG_INFO(0, param) +ZEND_END_ARG_INFO() + ZEPHIR_INIT_FUNCS(stub_mcall_method_entry) { #if PHP_VERSION_ID >= 80000 PHP_ME(Stub_Mcall, testMethod1, arginfo_stub_mcall_testmethod1, ZEND_ACC_PUBLIC) @@ -363,5 +368,6 @@ ZEPHIR_INIT_FUNCS(stub_mcall_method_entry) { #else PHP_ME(Stub_Mcall, issue1136, NULL, ZEND_ACC_PUBLIC) #endif + PHP_ME(Stub_Mcall, issue2245VarArgumentNullable, arginfo_stub_mcall_issue2245varargumentnullable, ZEND_ACC_PUBLIC) PHP_FE_END }; diff --git a/ext/stub/namespaces/classentry.zep.c b/ext/stub/namespaces/classentry.zep.c index 347d7d32a..772d6ab88 100644 --- a/ext/stub/namespaces/classentry.zep.c +++ b/ext/stub/namespaces/classentry.zep.c @@ -32,7 +32,7 @@ PHP_METHOD(Stub_Namespaces_ClassEntry, setParam) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(param, stub_namespaces_a_b_sub_ce) + Z_PARAM_OBJECT_OF_CLASS(param, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Namespaces\\A\\B\\Sub")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif @@ -53,7 +53,7 @@ PHP_METHOD(Stub_Namespaces_ClassEntry, setParamImported) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(param, stub_namespaces_a_b_sub_ce) + Z_PARAM_OBJECT_OF_CLASS(param, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Namespaces\\A\\B\\Sub")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/oo/ooparams.zep.c b/ext/stub/oo/ooparams.zep.c index 7f2c6be9c..3753665dc 100644 --- a/ext/stub/oo/ooparams.zep.c +++ b/ext/stub/oo/ooparams.zep.c @@ -576,7 +576,7 @@ PHP_METHOD(Stub_Oo_OoParams, setObjectClassCast) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(parameter, stub_oo_param_ce) + Z_PARAM_OBJECT_OF_CLASS(parameter, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Oo\\Param")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/reflection.zep.c b/ext/stub/reflection.zep.c index cbb95cba7..c58efa902 100644 --- a/ext/stub/reflection.zep.c +++ b/ext/stub/reflection.zep.c @@ -75,7 +75,7 @@ PHP_METHOD(Stub_Reflection, setReflectionParameter) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_ZVAL(parameter) + Z_PARAM_OBJECT_OF_CLASS(parameter, zend_lookup_class_ex(zend_string_init_fast(SL("\\\\ReflectionParameter")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/router.zep.c b/ext/stub/router.zep.c index f9a78747b..3949ca4be 100644 --- a/ext/stub/router.zep.c +++ b/ext/stub/router.zep.c @@ -164,7 +164,7 @@ PHP_METHOD(Stub_Router, setDI) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(dependencyInjector, stub_diinterface_ce) + Z_PARAM_OBJECT_OF_CLASS(dependencyInjector, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\DiInterface")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif @@ -566,7 +566,7 @@ PHP_METHOD(Stub_Router, handle) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(uri) + Z_PARAM_ZVAL_OR_NULL(uri) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1063,8 +1063,8 @@ PHP_METHOD(Stub_Router, add) ZEND_PARSE_PARAMETERS_START(1, 3) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) - Z_PARAM_ZVAL(httpMethods) + Z_PARAM_ZVAL_OR_NULL(paths) + Z_PARAM_ZVAL_OR_NULL(httpMethods) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1112,7 +1112,7 @@ PHP_METHOD(Stub_Router, addGet) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) + Z_PARAM_ZVAL_OR_NULL(paths) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1155,7 +1155,7 @@ PHP_METHOD(Stub_Router, addPost) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) + Z_PARAM_ZVAL_OR_NULL(paths) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1198,7 +1198,7 @@ PHP_METHOD(Stub_Router, addPut) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) + Z_PARAM_ZVAL_OR_NULL(paths) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1241,7 +1241,7 @@ PHP_METHOD(Stub_Router, addPatch) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) + Z_PARAM_ZVAL_OR_NULL(paths) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1284,7 +1284,7 @@ PHP_METHOD(Stub_Router, addDelete) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) + Z_PARAM_ZVAL_OR_NULL(paths) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1327,7 +1327,7 @@ PHP_METHOD(Stub_Router, addOptions) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) + Z_PARAM_ZVAL_OR_NULL(paths) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1370,7 +1370,7 @@ PHP_METHOD(Stub_Router, addHead) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) + Z_PARAM_ZVAL_OR_NULL(paths) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/router/route.zep.c b/ext/stub/router/route.zep.c index 5edf9c032..e5f4af8a2 100644 --- a/ext/stub/router/route.zep.c +++ b/ext/stub/router/route.zep.c @@ -66,8 +66,8 @@ PHP_METHOD(Stub_Router_Route, __construct) ZEND_PARSE_PARAMETERS_START(1, 3) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) - Z_PARAM_ZVAL(httpMethods) + Z_PARAM_ZVAL_OR_NULL(paths) + Z_PARAM_ZVAL_OR_NULL(httpMethods) ZEND_PARSE_PARAMETERS_END(); #endif @@ -498,7 +498,7 @@ PHP_METHOD(Stub_Router_Route, reConfigure) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_ZVAL(pattern) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(paths) + Z_PARAM_ZVAL_OR_NULL(paths) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/spectralnorm.zep.c b/ext/stub/spectralnorm.zep.c index 7f7de5c42..e018296dc 100644 --- a/ext/stub/spectralnorm.zep.c +++ b/ext/stub/spectralnorm.zep.c @@ -84,8 +84,8 @@ PHP_METHOD(Stub_SpectralNorm, Au) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_LONG(n) - Z_PARAM_OBJECT_OF_CLASS(u, spl_ce_SplFixedArray) - Z_PARAM_OBJECT_OF_CLASS(v, spl_ce_SplFixedArray) + Z_PARAM_OBJECT_OF_CLASS(u, zend_lookup_class_ex(zend_string_init_fast(SL("\\SplFixedArray")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(v, zend_lookup_class_ex(zend_string_init_fast(SL("\\SplFixedArray")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif @@ -167,8 +167,8 @@ PHP_METHOD(Stub_SpectralNorm, Atu) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_LONG(n) - Z_PARAM_OBJECT_OF_CLASS(u, spl_ce_SplFixedArray) - Z_PARAM_OBJECT_OF_CLASS(v, spl_ce_SplFixedArray) + Z_PARAM_OBJECT_OF_CLASS(u, zend_lookup_class_ex(zend_string_init_fast(SL("\\SplFixedArray")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(v, zend_lookup_class_ex(zend_string_init_fast(SL("\\SplFixedArray")), NULL, 0)) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/spropertyaccess.zep.c b/ext/stub/spropertyaccess.zep.c index 66aa4ebc7..a7f504409 100644 --- a/ext/stub/spropertyaccess.zep.c +++ b/ext/stub/spropertyaccess.zep.c @@ -84,7 +84,7 @@ PHP_METHOD(Stub_SPropertyAccess, testArgumentWithUnderscore) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(delimiter) + Z_PARAM_ZVAL_OR_NULL(delimiter) ZEND_PARSE_PARAMETERS_END(); #endif @@ -120,7 +120,7 @@ PHP_METHOD(Stub_SPropertyAccess, testArgument) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(delimiter) + Z_PARAM_ZVAL_OR_NULL(delimiter) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/strings.zep.c b/ext/stub/strings.zep.c index 07cb88b6e..dc24fee9a 100644 --- a/ext/stub/strings.zep.c +++ b/ext/stub/strings.zep.c @@ -45,7 +45,7 @@ PHP_METHOD(Stub_Strings, camelize) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(delimiter) + Z_PARAM_ZVAL_OR_NULL(delimiter) ZEND_PARSE_PARAMETERS_END(); #endif @@ -78,7 +78,7 @@ PHP_METHOD(Stub_Strings, uncamelize) ZEND_PARSE_PARAMETERS_START(1, 2) Z_PARAM_STR(str) Z_PARAM_OPTIONAL - Z_PARAM_ZVAL(delimiter) + Z_PARAM_ZVAL_OR_NULL(delimiter) ZEND_PARSE_PARAMETERS_END(); #endif From a57a3fa12795059c20f62a5fe8c95c54655bbd8a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 29 Jun 2021 04:26:29 +0000 Subject: [PATCH 04/35] Bump league/flysystem from 2.0.5 to 2.1.1 Bumps [league/flysystem](https://github.com/thephpleague/flysystem) from 2.0.5 to 2.1.1. - [Release notes](https://github.com/thephpleague/flysystem/releases) - [Changelog](https://github.com/thephpleague/flysystem/blob/2.x/CHANGELOG.md) - [Commits](https://github.com/thephpleague/flysystem/compare/2.0.5...2.1.1) --- updated-dependencies: - dependency-name: league/flysystem dependency-type: direct:production ... Signed-off-by: dependabot[bot] --- composer.lock | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/composer.lock b/composer.lock index af8c93e42..db33f7d73 100644 --- a/composer.lock +++ b/composer.lock @@ -207,16 +207,16 @@ }, { "name": "league/flysystem", - "version": "2.0.5", + "version": "2.1.1", "source": { "type": "git", "url": "https://github.com/thephpleague/flysystem.git", - "reference": "27ea64cc9d61ae7b6a5f04bebf062d89dd18e8f7" + "reference": "a3c694de9f7e844b76f9d1b61296ebf6e8d89d74" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/27ea64cc9d61ae7b6a5f04bebf062d89dd18e8f7", - "reference": "27ea64cc9d61ae7b6a5f04bebf062d89dd18e8f7", + "url": "https://api.github.com/repos/thephpleague/flysystem/zipball/a3c694de9f7e844b76f9d1b61296ebf6e8d89d74", + "reference": "a3c694de9f7e844b76f9d1b61296ebf6e8d89d74", "shasum": "" }, "require": { @@ -237,7 +237,8 @@ "google/cloud-storage": "^1.23", "phpseclib/phpseclib": "^2.0", "phpstan/phpstan": "^0.12.26", - "phpunit/phpunit": "^8.5 || ^9.4" + "phpunit/phpunit": "^8.5 || ^9.4", + "sabre/dav": "^4.1" }, "type": "library", "autoload": { @@ -271,7 +272,7 @@ ], "support": { "issues": "https://github.com/thephpleague/flysystem/issues", - "source": "https://github.com/thephpleague/flysystem/tree/2.0.5" + "source": "https://github.com/thephpleague/flysystem/tree/2.1.1" }, "funding": [ { @@ -287,7 +288,7 @@ "type": "tidelift" } ], - "time": "2021-04-11T15:03:35+00:00" + "time": "2021-06-23T22:07:10+00:00" }, { "name": "league/mime-type-detection", @@ -5233,5 +5234,5 @@ "ext-pdo_sqlite": "*", "ext-zip": "*" }, - "plugin-api-version": "2.0.0" + "plugin-api-version": "2.1.0" } From c2067beea2e027fe68df7e3d0e4bb24d65b8367d Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 12 Jul 2021 23:27:14 +0100 Subject: [PATCH 05/35] #2213 - Cleanup in getClassEntryByClassName() method --- Library/ClassDefinition.php | 67 ------------------------------------- 1 file changed, 67 deletions(-) diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index 591ad82e3..c590eea66 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1482,73 +1482,6 @@ public function getClassEntryByClassName( ): 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. - * - * TODO: Leave for future, maybe PHP code devs will make "reflection" ext public... - */ - /*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 From 6f7989968f4b0edd279fd02e343d0ba406a08141 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 12 Jul 2021 23:27:57 +0100 Subject: [PATCH 06/35] #2213 - Mark ClassDefinition:getClassEntryByClassName() method as deprecated --- Library/ClassDefinition.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index c590eea66..80c78b85d 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1469,6 +1469,8 @@ public function setAliasManager(AliasManager $aliasManager): void /** * Convert Class/Interface name to C ClassEntry. * + * @deprecated Use Zephir\Classes\Entry instead + * * @param string $className * @param CompilationContext $compilationContext * @param bool $check From 955b0971007574e9455d7bd830ecbf77729292c0 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 12 Jul 2021 23:29:00 +0100 Subject: [PATCH 07/35] #2213 - Move class entry detection into own class Entry --- Library/ClassMethod.php | 187 +++----------------------------------- Library/Classes/Entry.php | 98 ++++++++++++++++++++ 2 files changed, 110 insertions(+), 175 deletions(-) create mode 100644 Library/Classes/Entry.php diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index 8c8f8adf5..706148de9 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -13,6 +13,7 @@ namespace Zephir; +use Zephir\Classes\Entry as ClassEntry; use Zephir\Detectors\WriteDetector; use Zephir\Documentation\Docblock; use Zephir\Documentation\DocblockParser; @@ -175,26 +176,6 @@ class ClassMethod */ protected ?CallGathererPass $callGathererPass = null; - /** - * All classes must be in lower case. - * - * @var string[] - */ - protected array $excludedClassEntries = [ - 'reflector', - 'reflectionexception', - 'reflection', - 'reflectionfunctionabstract', - 'reflectionfunction', - 'reflectionparameter', - 'reflectionclass', - 'reflectionobject', - 'reflectionmethod', - 'reflectionproperty', - 'reflectionextension', - 'reflectionzendextension', - ]; - /** * ClassMethod constructor. * @@ -2408,14 +2389,17 @@ public function detectParam(array $parameter, CompilationContext $compilationCon break; case 'variable': - if (isset($parameter['cast']) && $parameter['cast']['type'] === 'variable' && $parameter['cast']['value']) { - $classEntry = $this->detectClassNameEntry($parameter['cast']['value'], $compilationContext); - if ($classEntry !== null) { - if ($hasDefaultNull) { - $param = sprintf('Z_PARAM_OBJECT_OF_CLASS_OR_NULL(%s, %s)', $name, $classEntry); - } else { - $param = sprintf('Z_PARAM_OBJECT_OF_CLASS(%s, %s)', $name, $classEntry); - } + if ( + isset($parameter['cast']) && + $parameter['cast']['type'] === 'variable' && + $parameter['cast']['value'] && + $this->classDefinition !== null + ) { + $classEntry = (new ClassEntry($parameter['cast']['value'], $this->classDefinition->getNamespace(), $compilationContext))->get(); + if ($hasDefaultNull) { + $param = sprintf('Z_PARAM_OBJECT_OF_CLASS_OR_NULL(%s, %s)', $name, $classEntry); + } else { + $param = sprintf('Z_PARAM_OBJECT_OF_CLASS(%s, %s)', $name, $classEntry); } } @@ -2425,153 +2409,6 @@ public function detectParam(array $parameter, CompilationContext $compilationCon return $param; } - /** - * @param string $className - * @param CompilationContext $compilationContext - * @return string|null - * @throws Exception - */ - private function detectClassNameEntry(string $className, CompilationContext $compilationContext): ?string - { - if ($this->classDefinition === null) { - 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 (is_null($aliasManager)) { - return null; - } - if ($aliasManager->isAlias($className)) { - $isAlias = true; - $className = $aliasManager->getAlias($className); - } - - /** - * PSR - */ - /*if (strpos($className, 'Psr') === 0 || strpos($className, '\Psr') === 0) { - $className = ltrim($className, '\\'); - - $psrHeaderFiles = [ - 'psr_http_message' => [ - 'Psr\Http\Message\StreamInterface', - 'Psr\Http\Message\StreamFactoryInterface', - 'Psr\Http\Message\UriFactoryInterface', - 'Psr\Http\Message\UriInterface', - 'Psr\Http\Message\RequestInterface', - 'Psr\Http\Message\RequestFactoryInterface', - 'Psr\Http\Message\ResponseInterface', - 'Psr\Http\Message\ResponseFactoryInterface', - 'Psr\Http\Message\ServerRequestInterface', - 'Psr\Http\Message\ServerRequestFactoryInterface', - 'Psr\Http\Message\UploadedFileInterface', - 'Psr\Http\Message\UploadedFileFactoryInterface', - ], - 'psr_simple_cache' => [ - 'Psr\SimpleCache\CacheInterface', - 'Psr\SimpleCache\CacheException', - 'Psr\SimpleCache\InvalidArgumentException', - ], - 'psr_container' => [ - 'Psr\Container\ContainerInterface', - ], - 'psr_log' => [ - 'Psr\Log\AbstractLogger', - 'Psr\Log\LoggerInterface', - 'Psr\Log\LogLevel', - ], - 'psr_link' => [ - 'Psr\Link\EvolvableLinkInterface', - 'Psr\Link\EvolvableLinkProviderInterface', - 'Psr\Link\LinkInterface', - 'Psr\Link\LinkProviderInterface', - ], - 'psr_http_server_middleware' => [ - 'Psr\Http\Server\MiddlewareInterface', - ], - 'psr_http_server_handler' => [ - 'Psr\Http\Server\RequestHandlerInterface', - ], - ]; - foreach ($psrHeaderFiles as $file => $classes) { - if (in_array($className, $classes)) { - $compilationContext->headersManager->add('ext/psr/' . $file); - } - } - - return str_replace('\\', '', $className) . '_ce_ptr'; - } - - try { - return $this - ->classDefinition - ->getClassEntryByClassName( - preg_replace(['/^\\\\/'], '', $className), - $compilationContext, - false - ); - } catch (CompilerException $exception) { - // Continue below execution - }*/ - - $classNamespace = explode('\\', $className); - - /** - * Full namespace with class name - */ - if (strpos($className, '\\') === 0) { - $classNamespace = array_values(array_filter($classNamespace)); - $className = str_replace('\\', '\\\\', $className); - - /** - * External class - */ - if (count($classNamespace) === 1) { - return 'zend_lookup_class_ex(zend_string_init_fast(SL("'.$className.'")), NULL, 0)'; - } - - /** - * External class, we don't know its ClassEntry in C world. - */ - if (!preg_match('/^'.$classNamespace[0].'/', $this->classDefinition->getNamespace())) { - return 'zend_lookup_class_ex(zend_string_init_fast(SL("'.$className.'")), NULL, 0)'; - } - - $className = end($classNamespace); - array_pop($classNamespace); - } else { - /** - * Check for partial namespace specification - * Example: Oo\Param, while namespace at the top is Stub - */ - $className = end($classNamespace); - array_pop($classNamespace); - - if ($isAlias === false) { - array_unshift($classNamespace, $this->classDefinition->getNamespace()); - } - } - - $namespace = join('\\', $classNamespace); - $namespace = str_replace('\\', '\\\\', $namespace); - - return 'zend_lookup_class_ex(zend_string_init_fast(SL("\\\\'.$namespace.'\\\\'.$className.'")), NULL, 0)'; - - return (new ClassDefinition($namespace, $className))->getClassEntry(); - } - /** * Get data type of method's parameter * diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php new file mode 100644 index 000000000..b8570588c --- /dev/null +++ b/Library/Classes/Entry.php @@ -0,0 +1,98 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +declare(strict_types=1); + +namespace Zephir\Classes; + +use Zephir\ClassDefinition; +use Zephir\CompilationContext; +use Zephir\Exception; + +/** + * Zend Class Entry detector + */ +class Entry +{ + /** + * Class name + * + * As it was passed: partially or fully. + * + * @var string + */ + private string $classname; + + /** + * Class namespace + * + * From where it is called. + * + * @var string + */ + private string $classNamespace; + + /** + * @var CompilationContext + */ + private CompilationContext $compilationContext; + + /** + * Entry constructor. + * + * @param string $className + * @param string $classNamespace + * @param CompilationContext $compilationContext + */ + public function __construct(string $className, string $classNamespace, CompilationContext $compilationContext) + { + $this->classname = $className; + $this->classNamespace = $classNamespace; + $this->compilationContext = $compilationContext; + } + + /** + * @return string + * @throws Exception + */ + public function get(): string + { + $className = $this->compilationContext->getFullName($this->classname); + $classNamespace = explode('\\', $className); + + /** + * External class, we don't know its ClassEntry in C world. + */ + if (!$this->isInternalClass($classNamespace[0])) { + $className = str_replace('\\', '\\\\', $className); + + return 'zend_lookup_class_ex(zend_string_init_fast(SL("\\\\'.$className.'")), NULL, 0)'; + } + + $className = end($classNamespace); + array_pop($classNamespace); + $namespace = join('\\', $classNamespace); + + return (new ClassDefinition($namespace, $className))->getClassEntry(); + } + + /** + * Detect if start of namespace class + * belongs to project namespace. + * + * @param string $className + * @return bool + */ + public function isInternalClass(string $className): bool + { + return preg_match('/^'.$className.'/', $this->classNamespace) === 1; + } +} From 6729bd6f7b0adcd4ba4c1bfc541a2653d3e24539 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 12 Jul 2021 23:35:00 +0100 Subject: [PATCH 08/35] #2213 - Add `NAMESPACE_SEPARATOR` class constant --- Library/Classes/Entry.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php index b8570588c..856756f0c 100644 --- a/Library/Classes/Entry.php +++ b/Library/Classes/Entry.php @@ -22,6 +22,8 @@ */ class Entry { + public const NAMESPACE_SEPARATOR = '\\'; + /** * Class name * @@ -66,20 +68,25 @@ public function __construct(string $className, string $classNamespace, Compilati public function get(): string { $className = $this->compilationContext->getFullName($this->classname); - $classNamespace = explode('\\', $className); + $classNamespace = explode(self::NAMESPACE_SEPARATOR, $className); /** * External class, we don't know its ClassEntry in C world. */ if (!$this->isInternalClass($classNamespace[0])) { - $className = str_replace('\\', '\\\\', $className); + $className = str_replace(self::NAMESPACE_SEPARATOR, self::NAMESPACE_SEPARATOR.self::NAMESPACE_SEPARATOR, $className); - return 'zend_lookup_class_ex(zend_string_init_fast(SL("\\\\'.$className.'")), NULL, 0)'; + return sprintf( + 'zend_lookup_class_ex(zend_string_init_fast(SL("%s%s%s")), NULL, 0)', + self::NAMESPACE_SEPARATOR, + self::NAMESPACE_SEPARATOR, + $className + ); } $className = end($classNamespace); array_pop($classNamespace); - $namespace = join('\\', $classNamespace); + $namespace = join(self::NAMESPACE_SEPARATOR, $classNamespace); return (new ClassDefinition($namespace, $className))->getClassEntry(); } From ec183ba1fd1d423a82cc5b3c14629d50f81faa9a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 12 Jul 2021 23:43:37 +0100 Subject: [PATCH 09/35] #2213 - Fix code style --- Library/ClassMethod.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index 706148de9..6cc7e802a 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -2389,8 +2389,7 @@ public function detectParam(array $parameter, CompilationContext $compilationCon break; case 'variable': - if ( - isset($parameter['cast']) && + if (isset($parameter['cast']) && $parameter['cast']['type'] === 'variable' && $parameter['cast']['value'] && $this->classDefinition !== null From b12ec559869e13963dc6f69b11722187c1ecd1b7 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 18 Jul 2021 18:04:34 +0100 Subject: [PATCH 10/35] #2213 - Optimize imports --- Library/Operators/Other/InstanceOfOperator.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Library/Operators/Other/InstanceOfOperator.php b/Library/Operators/Other/InstanceOfOperator.php index a0c9f7c00..6bd84dcc6 100644 --- a/Library/Operators/Other/InstanceOfOperator.php +++ b/Library/Operators/Other/InstanceOfOperator.php @@ -13,12 +13,14 @@ use Zephir\CompilationContext; use Zephir\CompiledExpression; -use function Zephir\escape_class; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; -use function Zephir\fqcn; use Zephir\Operators\BaseOperator; +use function Zephir\escape_class; +use function Zephir\fqcn; + /** * InstanceOf. * @@ -31,11 +33,11 @@ class InstanceOfOperator extends BaseOperator * @param CompilationContext $context * * @throws CompilerException - * @throws \Zephir\Exception + * @throws Exception * * @return CompiledExpression */ - public function compile($expression, CompilationContext $context) + public function compile($expression, CompilationContext $context): CompiledExpression { $left = new Expression($expression['left']); $resolved = $left->compile($context); From aa852b829b3e6fa8b305f2424eb1cfa46fcae129 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 18 Jul 2021 21:13:56 +0100 Subject: [PATCH 11/35] #2213 - Update properties types in CompilationContext class --- Library/CompilationContext.php | 92 +++++++++++++++++----------------- 1 file changed, 47 insertions(+), 45 deletions(-) diff --git a/Library/CompilationContext.php b/Library/CompilationContext.php index d0c254b74..d58e69a1b 100644 --- a/Library/CompilationContext.php +++ b/Library/CompilationContext.php @@ -9,10 +9,14 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir; use Psr\Log\LoggerInterface; +use Zephir\Cache\FunctionCache; use Zephir\Exception\CompilerException; +use Zephir\Passes\StaticTypeInference; /** * CompilationContext. @@ -22,182 +26,180 @@ class CompilationContext { /** - * @var EventsManager + * @var EventsManager|null */ - public $eventsManager; + public ?EventsManager $eventsManager = null; /** * Compiler. * - * @var Compiler + * @var Compiler|null */ - public $compiler; + public ?Compiler $compiler = null; /** * Current code printer. * - * @var CodePrinter + * @var CodePrinter|null */ - public $codePrinter; + public ?CodePrinter $codePrinter = null; /** * Whether the current method is static or not. * * @var bool */ - public $staticContext; + public bool $staticContext = false; /** * Code printer for the header. * - * @var CodePrinter + * @var CodePrinter|null */ - public $headerPrinter; + public ?CodePrinter $headerPrinter = null; /** * Current symbol table. * - * @var SymbolTable + * @var SymbolTable|null */ - public $symbolTable; + public ?SymbolTable $symbolTable = null; /** * Type inference data. * - * @var \Zephir\Passes\StaticTypeInference + * @var StaticTypeInference|null */ - public $typeInference; + public ?StaticTypeInference $typeInference = null; /** * Represents the class currently being compiled. * - * @var ClassDefinition + * @var ClassDefinition|null */ - public $classDefinition; + public ?ClassDefinition $classDefinition = null; /** * Current method or function that being compiled. * - * @var ClassMethod|FunctionDefinition + * @var ClassMethod|FunctionDefinition|null */ - public $currentMethod; + public ?ClassMethod $currentMethod = null; /** * Methods warm-up. * - * @var MethodCallWarmUp + * @var MethodCallWarmUp|null */ - public $methodWarmUp; + public ?MethodCallWarmUp $methodWarmUp = null; /** * Represents the c-headers added to the file. * - * @var HeadersManager + * @var HeadersManager|null */ - public $headersManager; + public ?HeadersManager $headersManager = null; /** * Represents interned strings and concatenations made in the project. * - * @var StringsManager + * @var StringsManager|null */ - public $stringsManager; + public ?StringsManager $stringsManager = null; /** * Tells if the the compilation is being made inside a cycle/loop. * * @var int */ - public $insideCycle = 0; + public int $insideCycle = 0; /** * Tells if the the compilation is being made inside a try/catch block. * * @var int */ - public $insideTryCatch = 0; + public int $insideTryCatch = 0; /** * Tells if the the compilation is being made inside a switch. * * @var int */ - public $insideSwitch = 0; + public int $insideSwitch = 0; /** * Current cycle/loop block. * * @var array */ - public $cycleBlocks = []; + public array $cycleBlocks = []; /** * The current branch, variables declared in conditional branches * must be market if they're used out of those branches. */ - public $currentBranch = 0; + public int $currentBranch = 0; /** * Global consecutive for try/catch blocks. * * @var int */ - public $currentTryCatch = 0; + public int $currentTryCatch = 0; /** * Helps to create graphs of conditional/jump branches in a specific method. * - * @var BranchManager + * @var BranchManager|null */ - public $branchManager; + public ?BranchManager $branchManager = null; /** * Manages both function and method call caches. * - * @var CacheManager + * @var CacheManager|null */ - public $cacheManager; + public ?CacheManager $cacheManager = null; /** * Manages class renamings using keyword 'use'. * - * @var AliasManager + * @var AliasManager|null */ - public $aliasManager; + public ?AliasManager $aliasManager = null; /** * Function Cache. * - * @var Cache\FunctionCache + * @var FunctionCache|null */ - public $functionCache; + public ?FunctionCache $functionCache = null; /** * Global config. * - * @var Config + * @var Config|null */ - public $config; + public ?Config $config = null; /** * Global logger. * - * @var LoggerInterface + * @var LoggerInterface|null */ - public $logger; + public ?LoggerInterface $logger = null; /** * The current backend. * - * @var BaseBackend + * @var BaseBackend|null */ - public $backend; + public ?BaseBackend $backend = null; /** * Transform class/interface name to FQN format. * - * TODO: WHY WHY :'( - * * @param string $className * * @return string From 1b4aede3c008a736f561f3ceb7a28f7b290e64db Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 18 Jul 2021 21:14:55 +0100 Subject: [PATCH 12/35] #2213 - Fix typo --- tests/Extension/MCallTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Extension/MCallTest.php b/tests/Extension/MCallTest.php index d2f5a7e16..fbae3ce47 100644 --- a/tests/Extension/MCallTest.php +++ b/tests/Extension/MCallTest.php @@ -166,7 +166,7 @@ private function getReflection() return $this->reflection; } - public function testSouldThrowTypeErrorForOptionalBoolean1(): void + public function testShouldThrowTypeErrorForOptionalBoolean1(): void { $test = new Mcall(); From e2ba648fba58828059634ff6738dd1b0f2f5e284 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 18 Jul 2021 23:06:14 +0100 Subject: [PATCH 13/35] #2213 - Refactor `Entry` class --- Library/Classes/Entry.php | 52 ++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 15 deletions(-) diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php index 856756f0c..59385e19e 100644 --- a/Library/Classes/Entry.php +++ b/Library/Classes/Entry.php @@ -13,6 +13,7 @@ namespace Zephir\Classes; +use ReflectionException; use Zephir\ClassDefinition; use Zephir\CompilationContext; use Zephir\Exception; @@ -34,41 +35,55 @@ class Entry private string $classname; /** - * Class namespace - * - * From where it is called. - * - * @var string + * @var CompilationContext */ - private string $classNamespace; + private CompilationContext $compilationContext; /** - * @var CompilationContext + * @var bool */ - private CompilationContext $compilationContext; + private bool $isInternal = false; /** * Entry constructor. * * @param string $className - * @param string $classNamespace * @param CompilationContext $compilationContext */ - public function __construct(string $className, string $classNamespace, CompilationContext $compilationContext) + public function __construct(string $className, CompilationContext $compilationContext) { $this->classname = $className; - $this->classNamespace = $classNamespace; $this->compilationContext = $compilationContext; } /** * @return string * @throws Exception + * @throws ReflectionException */ public function get(): string { - $className = $this->compilationContext->getFullName($this->classname); - $classNamespace = explode(self::NAMESPACE_SEPARATOR, $className); + if (class_exists($this->classname)) { + $reflection = new \ReflectionClass($this->classname); + + /** + * Check if class is defined internally by an extension, or the core. + */ + if ($reflection->isInternal()) { + return sprintf( + 'zend_lookup_class_ex(zend_string_init_fast(SL("%s%s%s")), NULL, 0)', + self::NAMESPACE_SEPARATOR, + self::NAMESPACE_SEPARATOR, + $reflection->getName(), + ); + } + + $className = $reflection->getName(); + $classNamespace = explode(self::NAMESPACE_SEPARATOR, $reflection->getNamespaceName()); + } else { + $className = $this->compilationContext->getFullName($this->classname); + $classNamespace = explode(self::NAMESPACE_SEPARATOR, $className); + } /** * External class, we don't know its ClassEntry in C world. @@ -91,6 +106,11 @@ public function get(): string return (new ClassDefinition($namespace, $className))->getClassEntry(); } + public function isInternal(): bool + { + return $this->isInternal; + } + /** * Detect if start of namespace class * belongs to project namespace. @@ -98,8 +118,10 @@ public function get(): string * @param string $className * @return bool */ - public function isInternalClass(string $className): bool + private function isInternalClass(string $className): bool { - return preg_match('/^'.$className.'/', $this->classNamespace) === 1; + $this->isInternal = preg_match('/^'.$className.'/', $this->compilationContext->classDefinition->getNamespace()) === 1; + + return $this->isInternal; } } From 7e375dc7144db47abf1ca08b453da90932c10a07 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Sun, 18 Jul 2021 23:07:29 +0100 Subject: [PATCH 14/35] #2213 - Apply new class entry detection approach (where it currently possible) --- Library/ClassDefinition.php | 8 +++-- Library/ClassMethod.php | 2 +- .../Operators/Other/InstanceOfOperator.php | 30 ++++++---------- .../Operators/Other/NewInstanceOperator.php | 35 +++++++++---------- Library/Statements/ThrowStatement.php | 31 +++++++--------- 5 files changed, 46 insertions(+), 60 deletions(-) diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index 80c78b85d..05ce855b7 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -15,6 +15,7 @@ use ReflectionClass; use ReflectionException; +use Zephir\Classes\Entry; use Zephir\Documentation\Docblock; use Zephir\Documentation\DocblockParser; use Zephir\Exception\CompilerException; @@ -1122,14 +1123,13 @@ public function compile(CompilationContext $compilationContext): void $classEntry = $classExtendsDefinition->getClassEntry($compilationContext); } else { $classEntry = $this->getClassEntryByClassName($classExtendsDefinition->getName(), $compilationContext); + //$classEntryNew = (new Entry($classExtendsDefinition->getName(), $compilationContext))->get(); } if (self::TYPE_CLASS === $this->getType()) { $codePrinter->output('ZEPHIR_REGISTER_CLASS_EX('.$this->getNCNamespace().', '.$this->getName().', '.$namespace.', '.strtolower($this->getSCName($namespace)).', '.$classEntry.', '.$methodEntry.', '.$flags.');'); - $codePrinter->outputBlankLine(); } else { $codePrinter->output('ZEPHIR_REGISTER_INTERFACE_EX('.$this->getNCNamespace().', '.$this->getName().', '.$namespace.', '.strtolower($this->getSCName($namespace)).', '.$classEntry.', '.$methodEntry.');'); - $codePrinter->outputBlankLine(); } } else { if (self::TYPE_CLASS === $this->getType()) { @@ -1137,9 +1137,10 @@ public function compile(CompilationContext $compilationContext): void } else { $codePrinter->output('ZEPHIR_REGISTER_INTERFACE('.$this->getNCNamespace().', '.$this->getName().', '.$namespace.', '.strtolower($this->getSCName($namespace)).', '.$methodEntry.');'); } - $codePrinter->outputBlankLine(); } + $codePrinter->outputBlankLine(); + /** * Compile properties. */ @@ -1193,6 +1194,7 @@ public function compile(CompilationContext $compilationContext): void if ($compiler->isBundledInterface($interface)) { $classInterfaceDefinition = $compiler->getInternalClassDefinition($interface); $classEntry = $this->getClassEntryByClassName($classInterfaceDefinition->getName(), $compilationContext); + //$classEntry = (new Entry($classInterfaceDefinition->getName(), $compilationContext))->get(); } } diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index 6cc7e802a..cbd4bac05 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -2394,7 +2394,7 @@ public function detectParam(array $parameter, CompilationContext $compilationCon $parameter['cast']['value'] && $this->classDefinition !== null ) { - $classEntry = (new ClassEntry($parameter['cast']['value'], $this->classDefinition->getNamespace(), $compilationContext))->get(); + $classEntry = (new ClassEntry($parameter['cast']['value'], $compilationContext))->get(); if ($hasDefaultNull) { $param = sprintf('Z_PARAM_OBJECT_OF_CLASS_OR_NULL(%s, %s)', $name, $classEntry); } else { diff --git a/Library/Operators/Other/InstanceOfOperator.php b/Library/Operators/Other/InstanceOfOperator.php index 6bd84dcc6..29ad49545 100644 --- a/Library/Operators/Other/InstanceOfOperator.php +++ b/Library/Operators/Other/InstanceOfOperator.php @@ -9,8 +9,11 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; +use Zephir\Classes\Entry; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception; @@ -19,7 +22,6 @@ use Zephir\Operators\BaseOperator; use function Zephir\escape_class; -use function Zephir\fqcn; /** * InstanceOf. @@ -57,21 +59,7 @@ public function compile($expression, CompilationContext $context): CompiledExpre switch ($resolved->getType()) { case 'string': - $className = fqcn($resolvedVariable, $context->classDefinition->getNamespace(), $context->aliasManager); - - if ($context->compiler->isClass($className)) { - $classDefinition = $context->compiler->getClassDefinition($className); - $classEntry = $classDefinition->getClassEntry($context); - } else { - if (!class_exists($className, false)) { - $code = 'SL("'.$resolvedVariable.'")'; - } else { - $classEntry = $context->classDefinition->getClassEntryByClassName($className, $context, true); - if (!$classEntry) { - $code = 'SL("'.$resolvedVariable.'")'; - } - } - } + $classEntry = (new Entry($resolvedVariable, $context)); break; default: switch ($resolved->getType()) { @@ -84,7 +72,7 @@ public function compile($expression, CompilationContext $context): CompiledExpre } elseif (!$context->symbolTable->hasVariable($resolvedVariable)) { $className = $context->getFullName($resolvedVariable); - if ('Traversable' == $className) { + if ('Traversable' === $className) { $symbol = $context->backend->getVariableCode($symbolVariable); return new CompiledExpression('bool', 'zephir_zval_is_traversable('.$symbol.')', $expression); @@ -101,8 +89,10 @@ public function compile($expression, CompilationContext $context): CompiledExpre if (!class_exists($className, false)) { $code = 'SL("'.trim(escape_class($className), '\\').'")'; } else { - $classEntry = $context->classDefinition->getClassEntryByClassName($className, $context, true); - if (!$classEntry) { + $entry = (new Entry($resolvedVariable, $context)); + $classEntry = $entry->get(); + + if (!$entry->isInternal()) { $code = 'SL("'.trim(escape_class($className), '\\').'")'; } } @@ -138,7 +128,7 @@ public function compile($expression, CompilationContext $context): CompiledExpre return new CompiledExpression('bool', 'zephir_instance_of_ev('.$symbol.', '.$classEntry.')', $expression); } - private function prepareBackendSpecificCode($variable, CompilationContext $context) + private function prepareBackendSpecificCode($variable, CompilationContext $context): string { return strtr('Z_STRVAL_P(:p:name), Z_STRLEN_P(:p:name)', [ ':name' => $variable, diff --git a/Library/Operators/Other/NewInstanceOperator.php b/Library/Operators/Other/NewInstanceOperator.php index 069b8db91..d7c89e9d1 100644 --- a/Library/Operators/Other/NewInstanceOperator.php +++ b/Library/Operators/Other/NewInstanceOperator.php @@ -9,10 +9,16 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; +use ReflectionClass; +use ReflectionException; +use Zephir\Classes\Entry; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\MethodCall; @@ -32,14 +38,14 @@ class NewInstanceOperator extends BaseOperator /** * Creates a new instance. * - * @param $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws ReflectionException + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { $codePrinter = $compilationContext->codePrinter; @@ -153,29 +159,22 @@ public function compile(array $expression, CompilationContext $compilationContex $zendClassEntry = $compilationContext->cacheManager->getClassEntryCache()->get($classNameToFetch, false, $compilationContext); $classEntry = $zendClassEntry->getName(); } else { - $reflectionClass = new \ReflectionClass($className); + $reflectionClass = new ReflectionClass($className); if ($reflectionClass->isInterface()) { throw new CompilerException('Interfaces cannot be instantiated', $expression); - } else { - if (method_exists($reflectionClass, 'isTrait')) { - if ($reflectionClass->isTrait()) { - throw new CompilerException('Traits cannot be instantiated', $expression); - } - } } - $classEntry = $compilationContext->classDefinition->getClassEntryByClassName($className, $compilationContext, true); - if (!$classEntry) { - $classNameToFetch = 'SL("'.escape_class($className).'")'; - $zendClassEntry = $compilationContext->cacheManager->getClassEntryCache()->get($classNameToFetch, false, $compilationContext); - $classEntry = $zendClassEntry->getName(); - } else { - $symbolVariable->setAssociatedClass($reflectionClass); + if (method_exists($reflectionClass, 'isTrait') && $reflectionClass->isTrait()) { + throw new CompilerException('Traits cannot be instantiated', $expression); } + + $classEntry = (new Entry($reflectionClass->getName(), $compilationContext))->get(); + $symbolVariable->setAssociatedClass($reflectionClass); } $symbolVariable->setClassTypes($className); } + $compilationContext->backend->initObject($symbolVariable, $classEntry, $compilationContext); } } diff --git a/Library/Statements/ThrowStatement.php b/Library/Statements/ThrowStatement.php index 61add0b16..51b765d3e 100644 --- a/Library/Statements/ThrowStatement.php +++ b/Library/Statements/ThrowStatement.php @@ -9,15 +9,19 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Statements; -use function Zephir\add_slashes; +use Zephir\Classes\Entry; use Zephir\CodePrinter; use Zephir\CompilationContext; use Zephir\Compiler; use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; + +use function Zephir\add_slashes; use function Zephir\fqcn; /** @@ -30,7 +34,7 @@ class ThrowStatement extends StatementAbstract /** * @param CompilationContext $compilationContext * - * @throws CompilerException + * @throws Exception */ public function compile(CompilationContext $compilationContext) { @@ -68,25 +72,16 @@ public function compile(CompilationContext $compilationContext) } } else { if ($compilationContext->compiler->isBundledClass($className)) { - $classEntry = $compilationContext->classDefinition->getClassEntryByClassName( - $className, - $compilationContext, - true - ); - if ($classEntry) { - $message = $expr['parameters'][0]['parameter']['value']; - $this->throwStringException($codePrinter, $classEntry, $message, $expr); - - return; - } + $classEntry = (new Entry($className, $compilationContext))->get(); + $message = $expr['parameters'][0]['parameter']['value']; + $this->throwStringException($codePrinter, $classEntry, $message, $expr); + + return; } } } else { if (\in_array($expr['type'], ['string', 'char', 'int', 'double'])) { - $class = $compilationContext->classDefinition->getClassEntryByClassName( - 'Exception', - $compilationContext - ); + $class = (new Entry('Exception', $compilationContext))->get(); $this->throwStringException($codePrinter, $class, $expr['value'], $expr); @@ -151,7 +146,7 @@ public function compile(CompilationContext $compilationContext) * @param string $message * @param array $expression */ - private function throwStringException(CodePrinter $printer, $class, $message, $expression) + private function throwStringException(CodePrinter $printer, string $class, string $message, array $expression): void { $message = add_slashes($message); $path = Compiler::getShortUserPath($expression['file']); From 49078ca1513f079e214a0f4829bcec6301673282 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 19 Jul 2021 20:00:07 +0100 Subject: [PATCH 15/35] #2213 - Change usage of `zend_string_init_fast` to `zend_string_init` --- Library/Classes/Entry.php | 41 +++++++++++++++++++++++++++------------ 1 file changed, 29 insertions(+), 12 deletions(-) diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php index 59385e19e..3685e0418 100644 --- a/Library/Classes/Entry.php +++ b/Library/Classes/Entry.php @@ -13,6 +13,7 @@ namespace Zephir\Classes; +use ReflectionClass; use ReflectionException; use Zephir\ClassDefinition; use Zephir\CompilationContext; @@ -44,6 +45,10 @@ class Entry */ private bool $isInternal = false; + private array $undetectableClassEntries = [ + 'ArrayObject' => 'spl_ce_ArrayObject', + ]; + /** * Entry constructor. * @@ -52,8 +57,8 @@ class Entry */ public function __construct(string $className, CompilationContext $compilationContext) { - $this->classname = $className; $this->compilationContext = $compilationContext; + $this->classname = $this->compilationContext->getFullName($className); } /** @@ -63,25 +68,34 @@ public function __construct(string $className, CompilationContext $compilationCo */ public function get(): string { + if (isset($this->undetectableClassEntries[$this->classname])) { + $this->compilationContext->headersManager->add('ext/spl/spl_array'); + + return $this->undetectableClassEntries[$this->classname]; + } + if (class_exists($this->classname)) { - $reflection = new \ReflectionClass($this->classname); + $reflection = new ReflectionClass($this->classname); + $className = $reflection->getName(); /** * Check if class is defined internally by an extension, or the core. */ if ($reflection->isInternal()) { return sprintf( - 'zend_lookup_class_ex(zend_string_init_fast(SL("%s%s%s")), NULL, 0)', - self::NAMESPACE_SEPARATOR, - self::NAMESPACE_SEPARATOR, - $reflection->getName(), + 'zend_lookup_class_ex(zend_string_init(ZEND_STRL("%s"), 0), NULL, 0)', + sprintf( + '%s%s%s', + self::NAMESPACE_SEPARATOR, + self::NAMESPACE_SEPARATOR, + $reflection->getName(), + ), ); } - $className = $reflection->getName(); $classNamespace = explode(self::NAMESPACE_SEPARATOR, $reflection->getNamespaceName()); } else { - $className = $this->compilationContext->getFullName($this->classname); + $className = $this->classname; $classNamespace = explode(self::NAMESPACE_SEPARATOR, $className); } @@ -92,10 +106,13 @@ public function get(): string $className = str_replace(self::NAMESPACE_SEPARATOR, self::NAMESPACE_SEPARATOR.self::NAMESPACE_SEPARATOR, $className); return sprintf( - 'zend_lookup_class_ex(zend_string_init_fast(SL("%s%s%s")), NULL, 0)', - self::NAMESPACE_SEPARATOR, - self::NAMESPACE_SEPARATOR, - $className + 'zend_lookup_class_ex(zend_string_init(ZEND_STRL("%s"), 0), NULL, 0)', + sprintf( + '%s%s%s', + self::NAMESPACE_SEPARATOR, + self::NAMESPACE_SEPARATOR, + $className, + ), ); } From a04cec5476057fdc54f45745d911e83d9b2c720a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 19 Jul 2021 20:00:26 +0100 Subject: [PATCH 16/35] #2213 - Optimize imports --- Library/Statements/ThrowStatement.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Library/Statements/ThrowStatement.php b/Library/Statements/ThrowStatement.php index 51b765d3e..70a7e3832 100644 --- a/Library/Statements/ThrowStatement.php +++ b/Library/Statements/ThrowStatement.php @@ -13,6 +13,7 @@ namespace Zephir\Statements; +use ReflectionException; use Zephir\Classes\Entry; use Zephir\CodePrinter; use Zephir\CompilationContext; @@ -21,6 +22,7 @@ use Zephir\Exception\CompilerException; use Zephir\Expression; +use function in_array; use function Zephir\add_slashes; use function Zephir\fqcn; @@ -35,6 +37,7 @@ class ThrowStatement extends StatementAbstract * @param CompilationContext $compilationContext * * @throws Exception + * @throws ReflectionException */ public function compile(CompilationContext $compilationContext) { @@ -72,7 +75,7 @@ public function compile(CompilationContext $compilationContext) } } else { if ($compilationContext->compiler->isBundledClass($className)) { - $classEntry = (new Entry($className, $compilationContext))->get(); + $classEntry = (new Entry($expr['class'], $compilationContext))->get(); $message = $expr['parameters'][0]['parameter']['value']; $this->throwStringException($codePrinter, $classEntry, $message, $expr); @@ -80,7 +83,7 @@ public function compile(CompilationContext $compilationContext) } } } else { - if (\in_array($expr['type'], ['string', 'char', 'int', 'double'])) { + if (in_array($expr['type'], ['string', 'char', 'int', 'double'])) { $class = (new Entry('Exception', $compilationContext))->get(); $this->throwStringException($codePrinter, $class, $expr['value'], $expr); @@ -97,7 +100,7 @@ public function compile(CompilationContext $compilationContext) throw new CompilerException($e->getMessage(), $expr, $e->getCode(), $e); } - if (!\in_array($resolvedExpr->getType(), ['variable', 'string'])) { + if (!in_array($resolvedExpr->getType(), ['variable', 'string'])) { throw new CompilerException( "Expression '".$resolvedExpr->getType().'" cannot be used as exception', $expr @@ -110,7 +113,7 @@ public function compile(CompilationContext $compilationContext) $expr ); - if (!\in_array($variableVariable->getType(), ['variable', 'string'])) { + if (!in_array($variableVariable->getType(), ['variable', 'string'])) { throw new CompilerException( "Variable '".$variableVariable->getType()."' cannot be used as exception", $expr From ba9d42a879b468cb2dc9353fb50b45307eaba897 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Mon, 19 Jul 2021 20:08:01 +0100 Subject: [PATCH 17/35] #2213 - Fix class name passer --- Library/ClassDefinition.php | 2 +- Library/Operators/Other/InstanceOfOperator.php | 6 +++--- Library/Operators/Other/NewInstanceOperator.php | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index 05ce855b7..2d35f8e1a 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1123,7 +1123,7 @@ public function compile(CompilationContext $compilationContext): void $classEntry = $classExtendsDefinition->getClassEntry($compilationContext); } else { $classEntry = $this->getClassEntryByClassName($classExtendsDefinition->getName(), $compilationContext); - //$classEntryNew = (new Entry($classExtendsDefinition->getName(), $compilationContext))->get(); + //$classEntry = (new Entry($classExtendsDefinition->getCompleteName(), $compilationContext))->get(); } if (self::TYPE_CLASS === $this->getType()) { diff --git a/Library/Operators/Other/InstanceOfOperator.php b/Library/Operators/Other/InstanceOfOperator.php index 29ad49545..3ae5f55fb 100644 --- a/Library/Operators/Other/InstanceOfOperator.php +++ b/Library/Operators/Other/InstanceOfOperator.php @@ -13,6 +13,7 @@ namespace Zephir\Operators\Other; +use ReflectionException; use Zephir\Classes\Entry; use Zephir\CompilationContext; use Zephir\CompiledExpression; @@ -34,10 +35,9 @@ class InstanceOfOperator extends BaseOperator * @param $expression * @param CompilationContext $context * - * @throws CompilerException - * @throws Exception - * * @return CompiledExpression + * @throws Exception + * @throws ReflectionException */ public function compile($expression, CompilationContext $context): CompiledExpression { diff --git a/Library/Operators/Other/NewInstanceOperator.php b/Library/Operators/Other/NewInstanceOperator.php index d7c89e9d1..ef4629dcc 100644 --- a/Library/Operators/Other/NewInstanceOperator.php +++ b/Library/Operators/Other/NewInstanceOperator.php @@ -168,7 +168,7 @@ public function compile(array $expression, CompilationContext $compilationContex throw new CompilerException('Traits cannot be instantiated', $expression); } - $classEntry = (new Entry($reflectionClass->getName(), $compilationContext))->get(); + $classEntry = (new Entry($expression['class'], $compilationContext))->get(); $symbolVariable->setAssociatedClass($reflectionClass); } From d55d2f1737c5eda83e9507102a3622b4e28c1cba Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Thu, 5 Aug 2021 21:21:07 +0100 Subject: [PATCH 18/35] #2213 - Partial regenerate of ext/ directory --- ext/stub/extendedinterface.zep.c | 2 +- ext/stub/flow.zep.c | 4 ++-- ext/stub/instance.zep.c | 22 ++++++++++---------- ext/stub/interfaces/implementinterface.zep.c | 4 ++-- ext/stub/issue2165/issue.zep.c | 2 +- ext/stub/namespaces/classentry.zep.c | 4 ++-- ext/stub/oo/ooparams.zep.c | 2 +- ext/stub/router.zep.c | 2 +- ext/stub/spectralnorm.zep.c | 8 +++---- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/ext/stub/extendedinterface.zep.c b/ext/stub/extendedinterface.zep.c index 8b2f0d5ef..e0f49d286 100644 --- a/ext/stub/extendedinterface.zep.c +++ b/ext/stub/extendedinterface.zep.c @@ -16,7 +16,7 @@ ZEPHIR_INIT_CLASS(Stub_ExtendedInterface) { ZEPHIR_REGISTER_INTERFACE(Stub, ExtendedInterface, stub, extendedinterface, NULL); - zend_class_implements(stub_extendedinterface_ce, 1, zephir_get_internal_ce(SL("iteratoraggregate"))); + zend_class_implements(stub_extendedinterface_ce, 1, zend_ce_aggregate); zend_class_implements(stub_extendedinterface_ce, 1, zend_ce_countable); return SUCCESS; } diff --git a/ext/stub/flow.zep.c b/ext/stub/flow.zep.c index 207a8f906..cc39ee4a7 100644 --- a/ext/stub/flow.zep.c +++ b/ext/stub/flow.zep.c @@ -1929,7 +1929,7 @@ PHP_METHOD(Stub_Flow, testFor33) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(e, zend_lookup_class_ex(zend_string_init_fast(SL("\\Iterator")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(e, zend_ce_iterator) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1967,7 +1967,7 @@ PHP_METHOD(Stub_Flow, testFor34) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(0, 1) Z_PARAM_OPTIONAL - Z_PARAM_OBJECT_OF_CLASS_OR_NULL(e, zend_lookup_class_ex(zend_string_init_fast(SL("\\Iterator")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS_OR_NULL(e, zend_ce_iterator) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/instance.zep.c b/ext/stub/instance.zep.c index 6bef3fe40..e0b503c8d 100644 --- a/ext/stub/instance.zep.c +++ b/ext/stub/instance.zep.c @@ -48,17 +48,17 @@ PHP_METHOD(Stub_Instance, __construct) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(11, 11) - Z_PARAM_OBJECT_OF_CLASS(a1, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Arithmetic")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a2, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\ArrayObject")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a3, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Assign")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a4, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Bitwise")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a5, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\BranchPrediction")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a6, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Cast")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a7, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Cblock")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a8, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Chars")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a9, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Closures")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a10, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Compare")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(a11, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Concat")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(a1, stub_arithmetic_ce) + Z_PARAM_OBJECT_OF_CLASS(a2, stub_arrayobject_ce) + Z_PARAM_OBJECT_OF_CLASS(a3, stub_assign_ce) + Z_PARAM_OBJECT_OF_CLASS(a4, stub_bitwise_ce) + Z_PARAM_OBJECT_OF_CLASS(a5, stub_branchprediction_ce) + Z_PARAM_OBJECT_OF_CLASS(a6, stub_cast_ce) + Z_PARAM_OBJECT_OF_CLASS(a7, stub_cblock_ce) + Z_PARAM_OBJECT_OF_CLASS(a8, stub_chars_ce) + Z_PARAM_OBJECT_OF_CLASS(a9, stub_closures_ce) + Z_PARAM_OBJECT_OF_CLASS(a10, stub_compare_ce) + Z_PARAM_OBJECT_OF_CLASS(a11, stub_concat_ce) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/interfaces/implementinterface.zep.c b/ext/stub/interfaces/implementinterface.zep.c index 6d499a0dc..a893ad41e 100644 --- a/ext/stub/interfaces/implementinterface.zep.c +++ b/ext/stub/interfaces/implementinterface.zep.c @@ -37,7 +37,7 @@ PHP_METHOD(Stub_Interfaces_ImplementInterface, get) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(obj, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Interfaces\\InterfaceInt")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(obj, stub_interfaces_interfaceint_ce) ZEND_PARSE_PARAMETERS_END(); #endif @@ -60,7 +60,7 @@ PHP_METHOD(Stub_Interfaces_ImplementInterface, getVoid) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(obj, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Interfaces\\InterfaceInt")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(obj, stub_interfaces_interfaceint_ce) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/issue2165/issue.zep.c b/ext/stub/issue2165/issue.zep.c index bf2420ea3..720a3ce3b 100644 --- a/ext/stub/issue2165/issue.zep.c +++ b/ext/stub/issue2165/issue.zep.c @@ -559,7 +559,7 @@ PHP_METHOD(Stub_Issue2165_Issue, divideMatrix) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(b, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Issue2165\\Issue")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(b, stub_issue2165_issue_ce) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/namespaces/classentry.zep.c b/ext/stub/namespaces/classentry.zep.c index 772d6ab88..347d7d32a 100644 --- a/ext/stub/namespaces/classentry.zep.c +++ b/ext/stub/namespaces/classentry.zep.c @@ -32,7 +32,7 @@ PHP_METHOD(Stub_Namespaces_ClassEntry, setParam) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(param, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Namespaces\\A\\B\\Sub")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(param, stub_namespaces_a_b_sub_ce) ZEND_PARSE_PARAMETERS_END(); #endif @@ -53,7 +53,7 @@ PHP_METHOD(Stub_Namespaces_ClassEntry, setParamImported) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(param, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Namespaces\\A\\B\\Sub")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(param, stub_namespaces_a_b_sub_ce) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/oo/ooparams.zep.c b/ext/stub/oo/ooparams.zep.c index 3753665dc..7f2c6be9c 100644 --- a/ext/stub/oo/ooparams.zep.c +++ b/ext/stub/oo/ooparams.zep.c @@ -576,7 +576,7 @@ PHP_METHOD(Stub_Oo_OoParams, setObjectClassCast) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(parameter, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Oo\\Param")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(parameter, stub_oo_param_ce) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/router.zep.c b/ext/stub/router.zep.c index 3949ca4be..a68201c09 100644 --- a/ext/stub/router.zep.c +++ b/ext/stub/router.zep.c @@ -164,7 +164,7 @@ PHP_METHOD(Stub_Router, setDI) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(dependencyInjector, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\DiInterface")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(dependencyInjector, stub_diinterface_ce) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/spectralnorm.zep.c b/ext/stub/spectralnorm.zep.c index e018296dc..7f7de5c42 100644 --- a/ext/stub/spectralnorm.zep.c +++ b/ext/stub/spectralnorm.zep.c @@ -84,8 +84,8 @@ PHP_METHOD(Stub_SpectralNorm, Au) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_LONG(n) - Z_PARAM_OBJECT_OF_CLASS(u, zend_lookup_class_ex(zend_string_init_fast(SL("\\SplFixedArray")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(v, zend_lookup_class_ex(zend_string_init_fast(SL("\\SplFixedArray")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(u, spl_ce_SplFixedArray) + Z_PARAM_OBJECT_OF_CLASS(v, spl_ce_SplFixedArray) ZEND_PARSE_PARAMETERS_END(); #endif @@ -167,8 +167,8 @@ PHP_METHOD(Stub_SpectralNorm, Atu) bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(3, 3) Z_PARAM_LONG(n) - Z_PARAM_OBJECT_OF_CLASS(u, zend_lookup_class_ex(zend_string_init_fast(SL("\\SplFixedArray")), NULL, 0)) - Z_PARAM_OBJECT_OF_CLASS(v, zend_lookup_class_ex(zend_string_init_fast(SL("\\SplFixedArray")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(u, spl_ce_SplFixedArray) + Z_PARAM_OBJECT_OF_CLASS(v, spl_ce_SplFixedArray) ZEND_PARSE_PARAMETERS_END(); #endif From 5eb4ee8a5f1e8252f16b3f712ea00a63bb3d1755 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Thu, 5 Aug 2021 21:25:59 +0100 Subject: [PATCH 19/35] #2213 - Partial regenerate of ext/ directory --- ext/stub/exceptions.zep.c | 14 +++++++------- ext/stub/instanceoff.zep.c | 2 +- ext/stub/mcall.zep.c | 4 ++-- ext/stub/trytest.zep.c | 24 ++++++++++++------------ 4 files changed, 22 insertions(+), 22 deletions(-) diff --git a/ext/stub/exceptions.zep.c b/ext/stub/exceptions.zep.c index 637687549..bf6aea1eb 100644 --- a/ext/stub/exceptions.zep.c +++ b/ext/stub/exceptions.zep.c @@ -183,19 +183,19 @@ PHP_METHOD(Stub_Exceptions, testExceptionLiteral) do { if (ZEPHIR_IS_STRING(&type, "string")) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(zend_ce_exception, "Test", "stub/exceptions.zep", 56); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(stub_exception_ce, "Test", "stub/exceptions.zep", 56); return; } if (ZEPHIR_IS_STRING(&type, "char")) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(zend_ce_exception, "t", "stub/exceptions.zep", 58); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(stub_exception_ce, "t", "stub/exceptions.zep", 58); return; } if (ZEPHIR_IS_STRING(&type, "int")) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(zend_ce_exception, "123", "stub/exceptions.zep", 60); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(stub_exception_ce, "123", "stub/exceptions.zep", 60); return; } if (ZEPHIR_IS_STRING(&type, "double")) { - ZEPHIR_THROW_EXCEPTION_DEBUG_STR(zend_ce_exception, "123.123", "stub/exceptions.zep", 62); + ZEPHIR_THROW_EXCEPTION_DEBUG_STR(stub_exception_ce, "123.123", "stub/exceptions.zep", 62); return; } } while(0); @@ -293,7 +293,7 @@ PHP_METHOD(Stub_Exceptions, testExceptionRethrow) ZEPHIR_INIT_VAR(&_0); ZVAL_OBJ(&_0, EG(exception)); Z_ADDREF_P(&_0); - if (zephir_instance_of_ev(&_0, zend_ce_exception)) { + if (zephir_is_instance_of(&_0, SL("Exception"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&e, &_0); zephir_throw_exception_debug(&e, "stub/exceptions.zep", 83); @@ -369,7 +369,7 @@ PHP_METHOD(Stub_Exceptions, testMultiException) return; } } else { - if (zephir_instance_of_ev(&_0, zend_ce_exception)) { + if (zephir_is_instance_of(&_0, SL("Exception"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&e, &_0); _3$$7 = zephir_is_callable(&exc); @@ -451,7 +451,7 @@ PHP_METHOD(Stub_Exceptions, issue1325) ZEPHIR_INIT_VAR(&_0); ZVAL_OBJ(&_0, EG(exception)); Z_ADDREF_P(&_0); - if (zephir_instance_of_ev(&_0, zend_ce_exception)) { + if (zephir_is_instance_of(&_0, SL("Exception"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&e, &_0); ZEPHIR_INIT_NVAR(&status); diff --git a/ext/stub/instanceoff.zep.c b/ext/stub/instanceoff.zep.c index c0deb966d..a13582d99 100644 --- a/ext/stub/instanceoff.zep.c +++ b/ext/stub/instanceoff.zep.c @@ -41,7 +41,7 @@ PHP_METHOD(Stub_Instanceoff, testInstanceOf1) ZEPHIR_INIT_VAR(&a); object_init(&a); - RETURN_MM_BOOL(zephir_instance_of_ev(&a, zend_standard_class_def)); + RETURN_MM_BOOL(zephir_is_instance_of(&a, SL("stdClass"))); } PHP_METHOD(Stub_Instanceoff, testInstanceOf2) diff --git a/ext/stub/mcall.zep.c b/ext/stub/mcall.zep.c index 21abe5270..4c277c33e 100644 --- a/ext/stub/mcall.zep.c +++ b/ext/stub/mcall.zep.c @@ -1051,7 +1051,7 @@ PHP_METHOD(Stub_Mcall, testObjectParamCastStdClass) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(param, zend_lookup_class_ex(zend_string_init_fast(SL("\\StdClass")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(param, zend_standard_class_def) ZEND_PARSE_PARAMETERS_END(); #endif @@ -1072,7 +1072,7 @@ PHP_METHOD(Stub_Mcall, testObjectParamCastOoParam) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(param, zend_lookup_class_ex(zend_string_init_fast(SL("\\Stub\\Oo\\Param")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(param, stub_oo_param_ce) ZEND_PARSE_PARAMETERS_END(); #endif diff --git a/ext/stub/trytest.zep.c b/ext/stub/trytest.zep.c index 757a5c149..e71d7dce5 100644 --- a/ext/stub/trytest.zep.c +++ b/ext/stub/trytest.zep.c @@ -142,7 +142,7 @@ PHP_METHOD(Stub_TryTest, testTry3) ZVAL_OBJ(&_2, EG(exception)); Z_ADDREF_P(&_2); ZEPHIR_INIT_VAR(&_3); - if (zephir_instance_of_ev(&_2, zend_ce_exception)) { + if (zephir_is_instance_of(&_2, SL("Exception"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&_3, &_2); RETURN_MM_STRING("error"); @@ -212,12 +212,12 @@ PHP_METHOD(Stub_TryTest, testTry4) Z_ADDREF_P(&_4); ZEPHIR_INIT_VAR(&_5); ZEPHIR_INIT_VAR(&_6); - if (zephir_instance_of_ev(&_4, spl_ce_RuntimeException)) { + if (zephir_is_instance_of(&_4, SL("RuntimeException"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&_5, &_4); RETURN_MM_STRING("domain error"); } else { - if (zephir_instance_of_ev(&_4, zend_ce_exception)) { + if (zephir_is_instance_of(&_4, SL("Exception"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&_6, &_4); RETURN_MM_STRING("error"); @@ -286,12 +286,12 @@ PHP_METHOD(Stub_TryTest, testTry5) ZVAL_OBJ(&_4, EG(exception)); Z_ADDREF_P(&_4); ZEPHIR_INIT_VAR(&_5); - if (zephir_instance_of_ev(&_4, spl_ce_RuntimeException)) { + if (zephir_is_instance_of(&_4, SL("RuntimeException"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&_5, &_4); RETURN_MM_STRING("any error"); } else { - if (zephir_instance_of_ev(&_4, zend_ce_exception)) { + if (zephir_is_instance_of(&_4, SL("Exception"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&_5, &_4); RETURN_MM_STRING("any error"); @@ -359,12 +359,12 @@ PHP_METHOD(Stub_TryTest, testTry6) ZEPHIR_INIT_VAR(&_4); ZVAL_OBJ(&_4, EG(exception)); Z_ADDREF_P(&_4); - if (zephir_instance_of_ev(&_4, spl_ce_RuntimeException)) { + if (zephir_is_instance_of(&_4, SL("RuntimeException"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&e, &_4); RETURN_MM_STRING("domain error"); } else { - if (zephir_instance_of_ev(&_4, zend_ce_exception)) { + if (zephir_is_instance_of(&_4, SL("Exception"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&e, &_4); RETURN_MM_STRING("error"); @@ -432,12 +432,12 @@ PHP_METHOD(Stub_TryTest, testTry7) ZEPHIR_INIT_VAR(&_4); ZVAL_OBJ(&_4, EG(exception)); Z_ADDREF_P(&_4); - if (zephir_instance_of_ev(&_4, spl_ce_RuntimeException)) { + if (zephir_is_instance_of(&_4, SL("RuntimeException"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&e, &_4); RETURN_MM_STRING("any error"); } else { - if (zephir_instance_of_ev(&_4, zend_ce_exception)) { + if (zephir_is_instance_of(&_4, SL("Exception"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&e, &_4); RETURN_MM_STRING("any error"); @@ -525,7 +525,7 @@ PHP_METHOD(Stub_TryTest, testTry9) ZEPHIR_INIT_VAR(&_0); ZVAL_OBJ(&_0, EG(exception)); Z_ADDREF_P(&_0); - if (zephir_instance_of_ev(&_0, spl_ce_RuntimeException)) { + if (zephir_is_instance_of(&_0, SL("RuntimeException"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&e, &_0); RETURN_MM_STRING("domain error"); @@ -560,7 +560,7 @@ PHP_METHOD(Stub_TryTest, testTry10) ZEPHIR_INIT_VAR(&_0); ZVAL_OBJ(&_0, EG(exception)); Z_ADDREF_P(&_0); - if (zephir_instance_of_ev(&_0, spl_ce_RuntimeException)) { + if (zephir_is_instance_of(&_0, SL("RuntimeException"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&e, &_0); RETURN_MM_STRING("domain error"); @@ -592,7 +592,7 @@ PHP_METHOD(Stub_TryTest, testTry11) ZEPHIR_INIT_VAR(&_0); ZVAL_OBJ(&_0, EG(exception)); Z_ADDREF_P(&_0); - if (zephir_instance_of_ev(&_0, zend_ce_exception)) { + if (zephir_is_instance_of(&_0, SL("Exception"))) { zend_clear_exception(); ZEPHIR_CPY_WRT(&ex, &_0); } From bc52dc0c3781e6f229fad769db7b830220920bc9 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Thu, 5 Aug 2021 22:15:33 +0100 Subject: [PATCH 20/35] #2213 - Remove deprecated method `getClassEntryByClassName()` --- Library/ClassDefinition.php | 447 +----------------------------------- Library/Classes/Entry.php | 177 ++++++++++++-- ext/stub/reflection.zep.c | 2 +- 3 files changed, 163 insertions(+), 463 deletions(-) diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index 2d35f8e1a..1e23bdda6 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1122,8 +1122,7 @@ public function compile(CompilationContext $compilationContext): void if ($classExtendsDefinition instanceof self && !$classExtendsDefinition->isBundled()) { $classEntry = $classExtendsDefinition->getClassEntry($compilationContext); } else { - $classEntry = $this->getClassEntryByClassName($classExtendsDefinition->getName(), $compilationContext); - //$classEntry = (new Entry($classExtendsDefinition->getCompleteName(), $compilationContext))->get(); + $classEntry = (new Entry($classExtendsDefinition->getCompleteName(), $compilationContext))->get(); } if (self::TYPE_CLASS === $this->getType()) { @@ -1185,17 +1184,14 @@ public function compile(CompilationContext $compilationContext): void /** * Try to find the interface. */ - $classEntry = false; + $classEntry = null; if ($compiler->isInterface($interface)) { $classInterfaceDefinition = $compiler->getClassDefinition($interface); $classEntry = $classInterfaceDefinition->getClassEntry($compilationContext); - } else { - if ($compiler->isBundledInterface($interface)) { - $classInterfaceDefinition = $compiler->getInternalClassDefinition($interface); - $classEntry = $this->getClassEntryByClassName($classInterfaceDefinition->getName(), $compilationContext); - //$classEntry = (new Entry($classInterfaceDefinition->getName(), $compilationContext))->get(); - } + } elseif ($compiler->isBundledInterface($interface)) { + $classInterfaceDefinition = $compiler->getInternalClassDefinition($interface); + $classEntry = (new Entry('\\'.$classInterfaceDefinition->getName(), $compilationContext))->get(); } if (!$classEntry) { @@ -1468,439 +1464,6 @@ public function setAliasManager(AliasManager $aliasManager): void $this->aliasManager = $aliasManager; } - /** - * Convert Class/Interface name to C ClassEntry. - * - * @deprecated Use Zephir\Classes\Entry instead - * - * @param string $className - * @param CompilationContext $compilationContext - * @param bool $check - * @return string - * @throws CompilerException - */ - public function getClassEntryByClassName( - string $className, - CompilationContext $compilationContext, - bool $check = true - ): string { - $this->compiler = $compilationContext->compiler; - - switch (strtolower($className)) { - /** - * Zend exceptions - */ - case 'throwable': - $classEntry = 'zend_ce_throwable'; - break; - - case 'exception': - $classEntry = 'zend_ce_exception'; - break; - - case 'errorexception': - $classEntry = 'zend_ce_error_exception'; - break; - - case 'error': - $classEntry = 'zend_ce_error'; - break; - - case 'compileerror': - $classEntry = 'zend_ce_compile_error'; - break; - - case 'parseerror': - $classEntry = 'zend_ce_parse_error'; - break; - - case 'typeerror': - $classEntry = 'zend_ce_type_error'; - break; - - case 'argumentcounterror': - $classEntry = 'zend_ce_argument_count_error'; - break; - - case 'valueerror': - $classEntry = 'zend_ce_value_error'; - break; - - case 'arithmeticerror': - $classEntry = 'zend_ce_arithmetic_error'; - break; - - case 'divisionbyzeroerror': - $classEntry = 'zend_ce_division_by_zero_error'; - break; - - case 'unhandledmatcherror': - $classEntry = 'zend_ce_unhandled_match_error'; - break; - - /** - * Zend interfaces (Zend/zend_interfaces.h) - */ - case 'traversable': - $classEntry = 'zend_ce_traversable'; - break; - - case 'aggregate': - $classEntry = 'zend_ce_aggregate'; - break; - - case 'iterator': - $classEntry = 'zend_ce_iterator'; - break; - - case 'arrayaccess': - $classEntry = 'zend_ce_arrayaccess'; - break; - - case 'serializable': - $classEntry = 'zend_ce_serializable'; - break; - - case 'countable': - $classEntry = 'zend_ce_countable'; - break; - - case 'stringable': - $classEntry = 'zend_ce_stringable'; - break; - - /** - * SPL Exceptions - */ - case 'logicexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_LogicException'; - break; - - case 'badfunctioncallexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_BadFunctionCallException'; - break; - - case 'badmethodcallexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_BadMethodCallException'; - break; - - case 'domainexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_DomainException'; - break; - - case 'invalidargumentexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_InvalidArgumentException'; - break; - - case 'lengthexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_LengthException'; - break; - - case 'outofrangeexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_OutOfRangeException'; - break; - - case 'runtimeexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_RuntimeException'; - break; - - case 'outofboundsexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_OutOfBoundsException'; - break; - - case 'overflowexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_OverflowException'; - break; - - case 'rangeexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_RangeException'; - break; - - case 'underflowexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_UnderflowException'; - break; - - case 'unexpectedvalueexception': - $compilationContext->headersManager->add('ext/spl/spl_exceptions'); - $classEntry = 'spl_ce_UnexpectedValueException'; - break; - - /** - * SPL Iterators Interfaces (spl/spl_iterators.h) - */ - case 'recursiveiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_RecursiveIterator'; - break; - - case 'recursiveiteratoriterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_RecursiveIteratorIterator'; - break; - - case 'recursivetreeiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_RecursiveTreeIterator'; - break; - - case 'filteriterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_FilterIterator'; - break; - - case 'recursivefilteriterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_RecursiveFilterIterator'; - break; - - case 'parentiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_ParentIterator'; - break; - - case 'seekableiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_SeekableIterator'; - break; - - case 'limititerator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_LimitIterator'; - break; - - case 'cachingiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_CachingIterator'; - break; - - case 'recursivecachingiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_RecursiveCachingIterator'; - break; - - case 'outeriterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_OuterIterator'; - break; - - case 'iteratoriterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_IteratorIterator'; - break; - - case 'norewinditerator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_NoRewindIterator'; - break; - - case 'infiniteiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_InfiniteIterator'; - break; - - case 'emptyiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_EmptyIterator'; - break; - - case 'appenditerator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_AppendIterator'; - break; - - case 'regexiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_RegexIterator'; - break; - - case 'recursiveregexiterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_RecursiveRegexIterator'; - break; - - case 'directoryiterator': - $compilationContext->headersManager->add('ext/spl/spl_directory'); - $classEntry = 'spl_ce_DirectoryIterator'; - break; - - case 'filesystemiterator': - $compilationContext->headersManager->add('ext/spl/spl_directory'); - $classEntry = 'spl_ce_FilesystemIterator'; - break; - - case 'recursivedirectoryiterator': - $compilationContext->headersManager->add('ext/spl/spl_directory'); - $classEntry = 'spl_ce_RecursiveDirectoryIterator'; - break; - - case 'globiterator': - $compilationContext->headersManager->add('ext/spl/spl_directory'); - $classEntry = 'spl_ce_GlobIterator'; - break; - - case 'splfileobject': - $compilationContext->headersManager->add('ext/spl/spl_directory'); - $classEntry = 'spl_ce_SplFileObject'; - break; - - case 'spltempfileobject': - $compilationContext->headersManager->add('ext/spl/spl_directory'); - $classEntry = 'spl_ce_SplTempFileObject'; - break; - - case 'countable': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_Countable'; - break; - - case 'callbackfilteriterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_CallbackFilterIterator'; - break; - - case 'recursivecallbackfilteriterator': - $compilationContext->headersManager->add('ext/spl/spl_iterators'); - $classEntry = 'spl_ce_RecursiveCallbackFilterIterator'; - break; - - case 'arrayobject': - $compilationContext->headersManager->add('ext/spl/spl_array'); - $classEntry = 'spl_ce_ArrayObject'; - break; - - case 'splfixedarray': - $compilationContext->headersManager->add('ext/spl/spl_fixedarray'); - $classEntry = 'spl_ce_SplFixedArray'; - break; - - case 'splpriorityqueue': - $compilationContext->headersManager->add('ext/spl/spl_heap'); - $classEntry = 'spl_ce_SplPriorityQueue'; - break; - - case 'splfileinfo': - $compilationContext->headersManager->add('ext/spl/spl_directory'); - $classEntry = 'spl_ce_SplFileInfo'; - break; - - case 'splheap': - $compilationContext->headersManager->add('ext/spl/spl_heap'); - $classEntry = 'spl_ce_SplHeap'; - break; - - case 'splminheap': - $compilationContext->headersManager->add('ext/spl/spl_heap'); - $classEntry = 'spl_ce_SplMinHeap'; - break; - - case 'splmaxheap': - $compilationContext->headersManager->add('ext/spl/spl_heap'); - $classEntry = 'spl_ce_SplMaxHeap'; - break; - - case 'splstack': - $compilationContext->headersManager->add('ext/spl/spl_dllist'); - $classEntry = 'spl_ce_SplStack'; - break; - - case 'splqueue': - $compilationContext->headersManager->add('ext/spl/spl_dllist'); - $classEntry = 'spl_ce_SplQueue'; - break; - - case 'spldoublylinkedlist': - $compilationContext->headersManager->add('ext/spl/spl_dllist'); - $classEntry = 'spl_ce_SplDoublyLinkedList'; - break; - - case 'stdclass': - $classEntry = 'zend_standard_class_def'; - break; - - case 'closure': - $compilationContext->headersManager->add('Zend/zend_closures'); - $classEntry = 'zend_ce_closure'; - break; - - case 'pdo': - $compilationContext->headersManager->add('ext/pdo/php_pdo_driver'); - $classEntry = 'php_pdo_get_dbh_ce()'; - break; - - case 'pdostatement': - $compilationContext->headersManager->add('kernel/main'); - $classEntry = $compilationContext->backend->fetchClassEntry('pdostatement'); - break; - - case 'pdoexception': - $compilationContext->headersManager->add('ext/pdo/php_pdo_driver'); - $classEntry = 'php_pdo_get_exception()'; - break; - - /** - * PHP Ext Date - */ - case 'datetimeinterface': - $compilationContext->headersManager->add('ext/date/php_date'); - $classEntry = 'php_date_get_interface_ce()'; - break; - - case 'datetime': - $compilationContext->headersManager->add('ext/date/php_date'); - $classEntry = 'php_date_get_date_ce()'; - break; - - case 'datetimeimmutable': - $compilationContext->headersManager->add('ext/date/php_date'); - $classEntry = 'php_date_get_immutable_ce()'; - break; - - case 'datetimezone': - $compilationContext->headersManager->add('ext/date/php_date'); - $classEntry = 'php_date_get_timezone_ce()'; - break; - - case 'dateinterval': - $compilationContext->headersManager->add('ext/date/php_date'); - $classEntry = 'php_date_get_interval_ce()'; - break; - - case 'dateperiod': - $compilationContext->headersManager->add('ext/date/php_date'); - $classEntry = 'php_date_get_period_ce()'; - break; - - /** - * PHP Ext session - */ - case 'sessionhandlerinterface': - $compilationContext->headersManager->add('ext/session/php_session'); - $classEntry = 'php_session_iface_entry'; - break; - - default: - if (!$check) { - throw new CompilerException('Unknown class entry for "'.$className.'"'); - } else { - $classEntry = $compilationContext->backend->fetchClassEntry(escape_class(strtolower($className))); - } - } - - return $classEntry; - } - /** * Builds a class definition from reflection. * diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php index 3685e0418..8c3096974 100644 --- a/Library/Classes/Entry.php +++ b/Library/Classes/Entry.php @@ -26,6 +26,15 @@ class Entry { public const NAMESPACE_SEPARATOR = '\\'; + private const EXT_SPL_ARRAY = 'ext/spl/spl_array'; + private const EXT_SPL_DIRECTORY = 'ext/spl/spl_directory'; + private const EXT_SPL_DLLIST = 'ext/spl/spl_dllist'; + private const EXT_SPL_EXCEPTIONS = 'ext/spl/spl_exceptions'; + private const EXT_SPL_FIXEDARRAY = 'ext/spl/spl_fixedarray'; + private const EXT_SPL_HEAP = 'ext/spl/spl_heap'; + private const EXT_SPL_ITERATORS = 'ext/spl/spl_iterators'; + private const EXT_SPL_OBSERVER = 'ext/spl/spl_observer'; + /** * Class name * @@ -45,8 +54,127 @@ class Entry */ private bool $isInternal = false; - private array $undetectableClassEntries = [ - 'ArrayObject' => 'spl_ce_ArrayObject', + private array $classEntries = [ + /** + * SPL + */ + 'ArrayObject' => ['spl_ce_ArrayObject', self::EXT_SPL_ARRAY], + 'ArrayIterator' => ['spl_ce_ArrayIterator', self::EXT_SPL_ARRAY], + 'RecursiveArrayIterator' => ['spl_ce_RecursiveArrayIterator', self::EXT_SPL_ARRAY], + + 'SplFileInfo' => ['spl_ce_SplFileInfo', self::EXT_SPL_DIRECTORY], + 'DirectoryIterator' => ['spl_ce_DirectoryIterator', self::EXT_SPL_DIRECTORY], + 'FilesystemIterator' => ['spl_ce_FilesystemIterator', self::EXT_SPL_DIRECTORY], + 'RecursiveDirectoryIterator' => ['spl_ce_RecursiveDirectoryIterator', self::EXT_SPL_DIRECTORY], + 'GlobIterator' => ['spl_ce_GlobIterator', self::EXT_SPL_DIRECTORY], + 'SplFileObject' => ['spl_ce_SplFileObject', self::EXT_SPL_DIRECTORY], + 'SplTempFileObject' => ['spl_ce_SplTempFileObject', self::EXT_SPL_DIRECTORY], + + 'SplDoublyLinkedList' => ['spl_ce_SplDoublyLinkedList', self::EXT_SPL_DLLIST], + 'SplQueue' => ['spl_ce_SplQueue', self::EXT_SPL_DLLIST], + 'SplStack' => ['spl_ce_SplStack', self::EXT_SPL_DLLIST], + + 'LogicException' => ['spl_ce_LogicException', self::EXT_SPL_EXCEPTIONS], + 'BadFunctionCallException' => ['spl_ce_BadFunctionCallException', self::EXT_SPL_EXCEPTIONS], + 'BadMethodCallException' => ['spl_ce_BadMethodCallException', self::EXT_SPL_EXCEPTIONS], + 'DomainException' => ['spl_ce_DomainException', self::EXT_SPL_EXCEPTIONS], + 'InvalidArgumentException' => ['spl_ce_InvalidArgumentException', self::EXT_SPL_EXCEPTIONS], + 'LengthException' => ['spl_ce_LengthException', self::EXT_SPL_EXCEPTIONS], + 'OutOfRangeException' => ['spl_ce_OutOfRangeException', self::EXT_SPL_EXCEPTIONS], + 'RuntimeException' => ['spl_ce_RuntimeException', self::EXT_SPL_EXCEPTIONS], + 'OutOfBoundsException' => ['spl_ce_OutOfBoundsException', self::EXT_SPL_EXCEPTIONS], + 'OverflowException' => ['spl_ce_OverflowException', self::EXT_SPL_EXCEPTIONS], + 'RangeException' => ['spl_ce_RangeException', self::EXT_SPL_EXCEPTIONS], + 'UnderflowException' => ['spl_ce_UnderflowException', self::EXT_SPL_EXCEPTIONS], + 'UnexpectedValueException' => ['spl_ce_UnexpectedValueException', self::EXT_SPL_EXCEPTIONS], + + 'SplFixedArray' => ['spl_ce_SplFixedArray', self::EXT_SPL_FIXEDARRAY], + + 'SplHeap' => ['spl_ce_SplHeap', self::EXT_SPL_HEAP], + 'SplMinHeap' => ['spl_ce_SplMinHeap', self::EXT_SPL_HEAP], + 'SplMaxHeap' => ['spl_ce_SplMaxHeap', self::EXT_SPL_HEAP], + 'SplPriorityQueue' => ['spl_ce_SplPriorityQueue', self::EXT_SPL_HEAP], + + 'AppendIterator' => ['spl_ce_AppendIterator', self::EXT_SPL_ITERATORS], + 'CachingIterator' => ['spl_ce_CachingIterator', self::EXT_SPL_ITERATORS], + 'CallbackFilterIterator' => ['spl_ce_CallbackFilterIterator', self::EXT_SPL_ITERATORS], + 'EmptyIterator' => ['spl_ce_EmptyIterator', self::EXT_SPL_ITERATORS], + 'FilterIterator' => ['spl_ce_FilterIterator', self::EXT_SPL_ITERATORS], + 'InfiniteIterator' => ['spl_ce_InfiniteIterator', self::EXT_SPL_ITERATORS], + 'IteratorIterator' => ['spl_ce_IteratorIterator', self::EXT_SPL_ITERATORS], + 'LimitIterator' => ['spl_ce_LimitIterator', self::EXT_SPL_ITERATORS], + 'NoRewindIterator' => ['spl_ce_NoRewindIterator', self::EXT_SPL_ITERATORS], + 'OuterIterator' => ['spl_ce_OuterIterator', self::EXT_SPL_ITERATORS], + 'ParentIterator' => ['spl_ce_ParentIterator', self::EXT_SPL_ITERATORS], + 'RecursiveCachingIterator' => ['spl_ce_RecursiveCachingIterator', self::EXT_SPL_ITERATORS], + 'RecursiveCallbackFilterIterator' => ['spl_ce_RecursiveCallbackFilterIterator', self::EXT_SPL_ITERATORS], + 'RecursiveFilterIterator' => ['spl_ce_RecursiveFilterIterator', self::EXT_SPL_ITERATORS], + 'RecursiveIterator' => ['spl_ce_RecursiveIterator', self::EXT_SPL_ITERATORS], + 'RecursiveIteratorIterator' => ['spl_ce_RecursiveIteratorIterator', self::EXT_SPL_ITERATORS], + 'RecursiveRegexIterator' => ['spl_ce_RecursiveRegexIterator', self::EXT_SPL_ITERATORS], + 'RecursiveTreeIterator' => ['spl_ce_RecursiveTreeIterator', self::EXT_SPL_ITERATORS], + 'RegexIterator' => ['spl_ce_RegexIterator', self::EXT_SPL_ITERATORS], + 'SeekableIterator' => ['spl_ce_SeekableIterator', self::EXT_SPL_ITERATORS], + + 'SplObserver' => ['spl_ce_SplObserver', self::EXT_SPL_OBSERVER], + 'SplSubject' => ['spl_ce_SplSubject', self::EXT_SPL_OBSERVER], + 'SplObjectStorage' => ['spl_ce_SplObjectStorage', self::EXT_SPL_OBSERVER], + 'MultipleIterator' => ['spl_ce_MultipleIterator', self::EXT_SPL_OBSERVER], + + /** + * Session + */ + 'SessionHandlerInterface' => ['php_session_iface_entry', 'ext/session/php_session'], + + /** + * Date + */ + 'DateTimeInterface' => ['php_date_get_interface_ce()', 'ext/date/php_date'], + 'DateTime' => ['php_date_get_date_ce()', 'ext/date/php_date'], + 'DateTimeImmutable' => ['php_date_get_immutable_ce()', 'ext/date/php_date'], + 'DateTimezone' => ['php_date_get_timezone_ce()', 'ext/date/php_date'], + 'DateInterval' => ['php_date_get_interval_ce()', 'ext/date/php_date'], + 'DatePeriod' => ['php_date_get_period_ce()', 'ext/date/php_date'], + + /** + * Closures + */ + 'Closure' => ['zend_ce_closure', 'Zend/zend_closures'], + + /** + * Zend exceptions + */ + 'Throwable' => ['zend_ce_throwable'], + 'Exception' => ['zend_ce_exception'], + 'ErrorException' => ['zend_ce_error_exception'], + 'Error' => ['zend_ce_error'], + 'CompileError' => ['zend_ce_compile_error'], + 'ParseError' => ['zend_ce_parse_error'], + 'TypeError' => ['zend_ce_type_error'], + 'ArgumentCountError' => ['zend_ce_argument_count_error'], + 'ValueError' => ['zend_ce_value_error'], + 'ArithmeticError' => ['zend_ce_arithmetic_error'], + 'DivisionByZeroError' => ['zend_ce_division_by_zero_error'], + 'UnhandledMatchError' => ['zend_ce_unhandled_match_error'], + + /** + * Zend interfaces (Zend/zend_interfaces.h) + */ + 'Traversable' => ['zend_ce_traversable'], + 'IteratorAggregate' => ['zend_ce_aggregate'], + 'Iterator' => ['zend_ce_iterator'], + 'ArrayAccess' => ['zend_ce_arrayaccess'], + 'Serializable' => ['zend_ce_serializable'], + 'Countable' => ['zend_ce_countable'], + 'Stringable' => ['zend_ce_stringable'], + + /** + * PDO + */ + 'PDO' => ['php_pdo_get_dbh_ce()', 'ext/pdo/php_pdo_driver'], + 'PDOException' => ['php_pdo_get_exception()', 'ext/pdo/php_pdo_driver'], + + 'stdClass' => ['zend_standard_class_def'], ]; /** @@ -59,6 +187,11 @@ public function __construct(string $className, CompilationContext $compilationCo { $this->compilationContext = $compilationContext; $this->classname = $this->compilationContext->getFullName($className); + + foreach ($this->classEntries as $key => $val) { + unset($this->classEntries[$key]); + $this->classEntries[strtolower($key)] = $val; + } } /** @@ -68,10 +201,23 @@ public function __construct(string $className, CompilationContext $compilationCo */ public function get(): string { - if (isset($this->undetectableClassEntries[$this->classname])) { - $this->compilationContext->headersManager->add('ext/spl/spl_array'); + $className = strtolower($this->classname); + + /** + * Exclusions + */ + if ($className === 'pdostatement') { + $this->compilationContext->headersManager->add('kernel/main'); + + return $this->compilationContext->backend->fetchClassEntry('pdostatement');; + } + + if (isset($this->classEntries[$className])) { + if (isset($this->classEntries[$className][1])) { + $this->compilationContext->headersManager->add($this->classEntries[$className][1]); + } - return $this->undetectableClassEntries[$this->classname]; + return $this->classEntries[$className][0]; } if (class_exists($this->classname)) { @@ -83,13 +229,8 @@ public function get(): string */ if ($reflection->isInternal()) { return sprintf( - 'zend_lookup_class_ex(zend_string_init(ZEND_STRL("%s"), 0), NULL, 0)', - sprintf( - '%s%s%s', - self::NAMESPACE_SEPARATOR, - self::NAMESPACE_SEPARATOR, - $reflection->getName(), - ), + 'zephir_get_internal_ce(SL("%s"))', + strtolower($reflection->getName()), ); } @@ -103,16 +244,12 @@ public function get(): string * External class, we don't know its ClassEntry in C world. */ if (!$this->isInternalClass($classNamespace[0])) { - $className = str_replace(self::NAMESPACE_SEPARATOR, self::NAMESPACE_SEPARATOR.self::NAMESPACE_SEPARATOR, $className); + $className = str_replace(self::NAMESPACE_SEPARATOR, self::NAMESPACE_SEPARATOR.self::NAMESPACE_SEPARATOR, strtolower($className)); return sprintf( - 'zend_lookup_class_ex(zend_string_init(ZEND_STRL("%s"), 0), NULL, 0)', - sprintf( - '%s%s%s', - self::NAMESPACE_SEPARATOR, - self::NAMESPACE_SEPARATOR, - $className, - ), + //'zend_lookup_class_ex(zend_string_init(ZEND_STRL("%s"), 0), NULL, 0)', + 'zephir_get_internal_ce(SL("%s"))', + $className, ); } diff --git a/ext/stub/reflection.zep.c b/ext/stub/reflection.zep.c index c58efa902..8628a8df6 100644 --- a/ext/stub/reflection.zep.c +++ b/ext/stub/reflection.zep.c @@ -75,7 +75,7 @@ PHP_METHOD(Stub_Reflection, setReflectionParameter) #if PHP_VERSION_ID >= 80000 bool is_null_true = 1; ZEND_PARSE_PARAMETERS_START(1, 1) - Z_PARAM_OBJECT_OF_CLASS(parameter, zend_lookup_class_ex(zend_string_init_fast(SL("\\\\ReflectionParameter")), NULL, 0)) + Z_PARAM_OBJECT_OF_CLASS(parameter, zephir_get_internal_ce(SL("reflectionparameter"))) ZEND_PARSE_PARAMETERS_END(); #endif From e7a044be83ea6ab1cdcbe0a6e77e1b9243e723f2 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Thu, 5 Aug 2021 22:18:53 +0100 Subject: [PATCH 21/35] #2213 - Move repetitive headers paths to class constants --- Library/Classes/Entry.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php index 8c3096974..d3bfda2aa 100644 --- a/Library/Classes/Entry.php +++ b/Library/Classes/Entry.php @@ -35,6 +35,11 @@ class Entry private const EXT_SPL_ITERATORS = 'ext/spl/spl_iterators'; private const EXT_SPL_OBSERVER = 'ext/spl/spl_observer'; + private const EXT_SESSION = 'ext/session/php_session'; + + private const EXT_DATE = 'ext/date/php_date'; + private const EXT_PDO = 'ext/pdo/php_pdo_driver'; + /** * Class name * @@ -124,17 +129,17 @@ class Entry /** * Session */ - 'SessionHandlerInterface' => ['php_session_iface_entry', 'ext/session/php_session'], + 'SessionHandlerInterface' => ['php_session_iface_entry', self::EXT_SESSION], /** * Date */ - 'DateTimeInterface' => ['php_date_get_interface_ce()', 'ext/date/php_date'], - 'DateTime' => ['php_date_get_date_ce()', 'ext/date/php_date'], - 'DateTimeImmutable' => ['php_date_get_immutable_ce()', 'ext/date/php_date'], - 'DateTimezone' => ['php_date_get_timezone_ce()', 'ext/date/php_date'], - 'DateInterval' => ['php_date_get_interval_ce()', 'ext/date/php_date'], - 'DatePeriod' => ['php_date_get_period_ce()', 'ext/date/php_date'], + 'DateTimeInterface' => ['php_date_get_interface_ce()', self::EXT_DATE], + 'DateTime' => ['php_date_get_date_ce()', self::EXT_DATE], + 'DateTimeImmutable' => ['php_date_get_immutable_ce()', self::EXT_DATE], + 'DateTimezone' => ['php_date_get_timezone_ce()', self::EXT_DATE], + 'DateInterval' => ['php_date_get_interval_ce()', self::EXT_DATE], + 'DatePeriod' => ['php_date_get_period_ce()', self::EXT_DATE], /** * Closures @@ -171,8 +176,8 @@ class Entry /** * PDO */ - 'PDO' => ['php_pdo_get_dbh_ce()', 'ext/pdo/php_pdo_driver'], - 'PDOException' => ['php_pdo_get_exception()', 'ext/pdo/php_pdo_driver'], + 'PDO' => ['php_pdo_get_dbh_ce()', self::EXT_PDO], + 'PDOException' => ['php_pdo_get_exception()', self::EXT_PDO], 'stdClass' => ['zend_standard_class_def'], ]; From efc507e126482938c1855d6355036b3108244c89 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Thu, 5 Aug 2021 22:20:17 +0100 Subject: [PATCH 22/35] #2213 - Fix code style --- Library/Classes/Entry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php index d3bfda2aa..0dbf05367 100644 --- a/Library/Classes/Entry.php +++ b/Library/Classes/Entry.php @@ -214,7 +214,7 @@ public function get(): string if ($className === 'pdostatement') { $this->compilationContext->headersManager->add('kernel/main'); - return $this->compilationContext->backend->fetchClassEntry('pdostatement');; + return $this->compilationContext->backend->fetchClassEntry('pdostatement'); } if (isset($this->classEntries[$className])) { From 50529334d1871bf0a40745d62c04a64aa3d74f61 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 10:24:23 +0100 Subject: [PATCH 23/35] #2213 - Remove unused method `processExpectedComplexLiteralReturn()` --- Library/Call.php | 36 ------------------------------------ 1 file changed, 36 deletions(-) diff --git a/Library/Call.php b/Library/Call.php index c443c7e70..0c6932fff 100644 --- a/Library/Call.php +++ b/Library/Call.php @@ -122,42 +122,6 @@ public function processExpectedObservedReturn(CompilationContext $compilationCon $this->isExpecting = $isExpecting; } - /** - * Processes the symbol variable that will be used to return - * the result of the symbol call. If a temporal variable is used - * as returned value only the body is freed between calls. - * - * @param CompilationContext $compilationContext - */ - public function processExpectedComplexLiteralReturn(CompilationContext $compilationContext) - { - $expr = $this->expression; - $expression = $expr->getExpression(); - - /** - * Create temporary variable if needed. - */ - $mustInit = false; - $isExpecting = $expr->isExpectingReturn(); - if ($isExpecting) { - $symbolVariable = $expr->getExpectingVariable(); - if (\is_object($symbolVariable)) { - $readDetector = new ReadDetector(); - if ($readDetector->detect($symbolVariable->getName(), $expression)) { - $symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression); - } else { - $mustInit = true; - } - } else { - $symbolVariable = $compilationContext->symbolTable->getTempComplexLiteralVariableForWrite('variable', $compilationContext, $expression); - } - } - - $this->mustInit = $mustInit; - $this->symbolVariable = $symbolVariable; - $this->isExpecting = $isExpecting; - } - /** * Check if an external expression is expecting the call return a value. * From fed76d8b43f9fe0403d6c1e284b2ef03dd6359dc Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 10:34:59 +0100 Subject: [PATCH 24/35] #2213 - Fix class name definition --- Library/ClassDefinition.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index 1e23bdda6..1fde834c5 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1122,7 +1122,8 @@ public function compile(CompilationContext $compilationContext): void if ($classExtendsDefinition instanceof self && !$classExtendsDefinition->isBundled()) { $classEntry = $classExtendsDefinition->getClassEntry($compilationContext); } else { - $classEntry = (new Entry($classExtendsDefinition->getCompleteName(), $compilationContext))->get(); + $className = method_exists($classExtendsDefinition, 'getCompleteName') ? $classExtendsDefinition->getCompleteName() : $classExtendsDefinition->getName(); + $classEntry = (new Entry($className, $compilationContext))->get(); } if (self::TYPE_CLASS === $this->getType()) { From 7b89aee7340b71eb39f35ad95b12aed61bb77b4f Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 10:42:55 +0100 Subject: [PATCH 25/35] #2213 - Minor code refactor --- Library/ClassConstant.php | 28 +++++++++++++--------------- Library/ClassDefinition.php | 8 ++------ 2 files changed, 15 insertions(+), 21 deletions(-) diff --git a/Library/ClassConstant.php b/Library/ClassConstant.php index bae66374b..4d49ad936 100644 --- a/Library/ClassConstant.php +++ b/Library/ClassConstant.php @@ -25,17 +25,17 @@ class ClassConstant /** * @var string */ - protected $name; + protected string $name; /** * @var array */ - protected $value = []; + protected array $value = []; /** * @var string */ - protected $docblock; + protected string $docblock; /** * ClassConstant constructor. @@ -44,7 +44,7 @@ class ClassConstant * @param array $value * @param string $docBlock */ - public function __construct($name, array $value, $docBlock) + public function __construct(string $name, array $value, string $docBlock) { $this->name = $name; $this->value = $value; @@ -56,7 +56,7 @@ public function __construct($name, array $value, $docBlock) * * @return string */ - public function getName() + public function getName(): string { return $this->name; } @@ -68,7 +68,7 @@ public function getName() * * @return array */ - public function getValue() + public function getValue(): array { return $this->value; } @@ -78,7 +78,7 @@ public function getValue() * * @return string */ - public function getValueType() + public function getValueType(): string { return $this->value['type']; } @@ -102,7 +102,7 @@ public function getValueValue() * * @return string */ - public function getDocBlock() + public function getDocBlock(): string { return $this->docblock; } @@ -112,7 +112,7 @@ public function getDocBlock() * * @return string */ - public function getType() + public function getType(): string { return $this->value['type']; } @@ -126,7 +126,7 @@ public function getType() */ public function processValue(CompilationContext $compilationContext) { - if ('constant' == $this->value['type']) { + if ('constant' === $this->value['type']) { $constant = new Constants(); $compiledExpression = $constant->compile($this->value, $compilationContext); @@ -138,7 +138,7 @@ public function processValue(CompilationContext $compilationContext) return; } - if ('static-constant-access' == $this->value['type']) { + if ('static-constant-access' === $this->value['type']) { $staticConstantAccess = new StaticConstantAccess(); $compiledExpression = $staticConstantAccess->compile($this->value, $compilationContext); @@ -146,8 +146,6 @@ public function processValue(CompilationContext $compilationContext) 'type' => $compiledExpression->getType(), 'value' => $compiledExpression->getCode(), ]; - - return; } } @@ -163,12 +161,12 @@ public function compile(CompilationContext $compilationContext) { $this->processValue($compilationContext); - $constanValue = isset($this->value['value']) ? $this->value['value'] : null; + $constantValue = $this->value['value'] ?? null; $compilationContext->backend->declareConstant( $this->value['type'], $this->getName(), - $constanValue, + $constantValue, $compilationContext ); } diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index 1fde834c5..9a84c6643 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -790,7 +790,7 @@ public function getMethod(string $methodName, bool $checkExtends = true): ?Class /** * Set a method and its body. * - * @param $methodName + * @param string $methodName * @param ClassMethod $method */ public function setMethod(string $methodName, ClassMethod $method): void @@ -1293,11 +1293,7 @@ public function compile(CompilationContext $compilationContext): void * Check whether classes must be exported. */ $exportClasses = $compilationContext->config->get('export-classes', 'extra'); - if ($exportClasses) { - $exportAPI = 'extern ZEPHIR_API'; - } else { - $exportAPI = 'extern'; - } + $exportAPI = $exportClasses ? 'extern ZEPHIR_API' : 'extern'; /** * Create a code printer for the header file. From d2eb57755fc4209ae0cd4c1843331fa12815b003 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 11:41:37 +0100 Subject: [PATCH 26/35] #2213 - Move class entries array into separate config file --- Library/Classes/Entry.php | 144 +++----------------------------------- config/class-entries.php | 138 ++++++++++++++++++++++++++++++++++++ 2 files changed, 146 insertions(+), 136 deletions(-) create mode 100644 config/class-entries.php diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php index 0dbf05367..b27996040 100644 --- a/Library/Classes/Entry.php +++ b/Library/Classes/Entry.php @@ -26,20 +26,6 @@ class Entry { public const NAMESPACE_SEPARATOR = '\\'; - private const EXT_SPL_ARRAY = 'ext/spl/spl_array'; - private const EXT_SPL_DIRECTORY = 'ext/spl/spl_directory'; - private const EXT_SPL_DLLIST = 'ext/spl/spl_dllist'; - private const EXT_SPL_EXCEPTIONS = 'ext/spl/spl_exceptions'; - private const EXT_SPL_FIXEDARRAY = 'ext/spl/spl_fixedarray'; - private const EXT_SPL_HEAP = 'ext/spl/spl_heap'; - private const EXT_SPL_ITERATORS = 'ext/spl/spl_iterators'; - private const EXT_SPL_OBSERVER = 'ext/spl/spl_observer'; - - private const EXT_SESSION = 'ext/session/php_session'; - - private const EXT_DATE = 'ext/date/php_date'; - private const EXT_PDO = 'ext/pdo/php_pdo_driver'; - /** * Class name * @@ -59,128 +45,12 @@ class Entry */ private bool $isInternal = false; - private array $classEntries = [ - /** - * SPL - */ - 'ArrayObject' => ['spl_ce_ArrayObject', self::EXT_SPL_ARRAY], - 'ArrayIterator' => ['spl_ce_ArrayIterator', self::EXT_SPL_ARRAY], - 'RecursiveArrayIterator' => ['spl_ce_RecursiveArrayIterator', self::EXT_SPL_ARRAY], - - 'SplFileInfo' => ['spl_ce_SplFileInfo', self::EXT_SPL_DIRECTORY], - 'DirectoryIterator' => ['spl_ce_DirectoryIterator', self::EXT_SPL_DIRECTORY], - 'FilesystemIterator' => ['spl_ce_FilesystemIterator', self::EXT_SPL_DIRECTORY], - 'RecursiveDirectoryIterator' => ['spl_ce_RecursiveDirectoryIterator', self::EXT_SPL_DIRECTORY], - 'GlobIterator' => ['spl_ce_GlobIterator', self::EXT_SPL_DIRECTORY], - 'SplFileObject' => ['spl_ce_SplFileObject', self::EXT_SPL_DIRECTORY], - 'SplTempFileObject' => ['spl_ce_SplTempFileObject', self::EXT_SPL_DIRECTORY], - - 'SplDoublyLinkedList' => ['spl_ce_SplDoublyLinkedList', self::EXT_SPL_DLLIST], - 'SplQueue' => ['spl_ce_SplQueue', self::EXT_SPL_DLLIST], - 'SplStack' => ['spl_ce_SplStack', self::EXT_SPL_DLLIST], - - 'LogicException' => ['spl_ce_LogicException', self::EXT_SPL_EXCEPTIONS], - 'BadFunctionCallException' => ['spl_ce_BadFunctionCallException', self::EXT_SPL_EXCEPTIONS], - 'BadMethodCallException' => ['spl_ce_BadMethodCallException', self::EXT_SPL_EXCEPTIONS], - 'DomainException' => ['spl_ce_DomainException', self::EXT_SPL_EXCEPTIONS], - 'InvalidArgumentException' => ['spl_ce_InvalidArgumentException', self::EXT_SPL_EXCEPTIONS], - 'LengthException' => ['spl_ce_LengthException', self::EXT_SPL_EXCEPTIONS], - 'OutOfRangeException' => ['spl_ce_OutOfRangeException', self::EXT_SPL_EXCEPTIONS], - 'RuntimeException' => ['spl_ce_RuntimeException', self::EXT_SPL_EXCEPTIONS], - 'OutOfBoundsException' => ['spl_ce_OutOfBoundsException', self::EXT_SPL_EXCEPTIONS], - 'OverflowException' => ['spl_ce_OverflowException', self::EXT_SPL_EXCEPTIONS], - 'RangeException' => ['spl_ce_RangeException', self::EXT_SPL_EXCEPTIONS], - 'UnderflowException' => ['spl_ce_UnderflowException', self::EXT_SPL_EXCEPTIONS], - 'UnexpectedValueException' => ['spl_ce_UnexpectedValueException', self::EXT_SPL_EXCEPTIONS], - - 'SplFixedArray' => ['spl_ce_SplFixedArray', self::EXT_SPL_FIXEDARRAY], - - 'SplHeap' => ['spl_ce_SplHeap', self::EXT_SPL_HEAP], - 'SplMinHeap' => ['spl_ce_SplMinHeap', self::EXT_SPL_HEAP], - 'SplMaxHeap' => ['spl_ce_SplMaxHeap', self::EXT_SPL_HEAP], - 'SplPriorityQueue' => ['spl_ce_SplPriorityQueue', self::EXT_SPL_HEAP], - - 'AppendIterator' => ['spl_ce_AppendIterator', self::EXT_SPL_ITERATORS], - 'CachingIterator' => ['spl_ce_CachingIterator', self::EXT_SPL_ITERATORS], - 'CallbackFilterIterator' => ['spl_ce_CallbackFilterIterator', self::EXT_SPL_ITERATORS], - 'EmptyIterator' => ['spl_ce_EmptyIterator', self::EXT_SPL_ITERATORS], - 'FilterIterator' => ['spl_ce_FilterIterator', self::EXT_SPL_ITERATORS], - 'InfiniteIterator' => ['spl_ce_InfiniteIterator', self::EXT_SPL_ITERATORS], - 'IteratorIterator' => ['spl_ce_IteratorIterator', self::EXT_SPL_ITERATORS], - 'LimitIterator' => ['spl_ce_LimitIterator', self::EXT_SPL_ITERATORS], - 'NoRewindIterator' => ['spl_ce_NoRewindIterator', self::EXT_SPL_ITERATORS], - 'OuterIterator' => ['spl_ce_OuterIterator', self::EXT_SPL_ITERATORS], - 'ParentIterator' => ['spl_ce_ParentIterator', self::EXT_SPL_ITERATORS], - 'RecursiveCachingIterator' => ['spl_ce_RecursiveCachingIterator', self::EXT_SPL_ITERATORS], - 'RecursiveCallbackFilterIterator' => ['spl_ce_RecursiveCallbackFilterIterator', self::EXT_SPL_ITERATORS], - 'RecursiveFilterIterator' => ['spl_ce_RecursiveFilterIterator', self::EXT_SPL_ITERATORS], - 'RecursiveIterator' => ['spl_ce_RecursiveIterator', self::EXT_SPL_ITERATORS], - 'RecursiveIteratorIterator' => ['spl_ce_RecursiveIteratorIterator', self::EXT_SPL_ITERATORS], - 'RecursiveRegexIterator' => ['spl_ce_RecursiveRegexIterator', self::EXT_SPL_ITERATORS], - 'RecursiveTreeIterator' => ['spl_ce_RecursiveTreeIterator', self::EXT_SPL_ITERATORS], - 'RegexIterator' => ['spl_ce_RegexIterator', self::EXT_SPL_ITERATORS], - 'SeekableIterator' => ['spl_ce_SeekableIterator', self::EXT_SPL_ITERATORS], - - 'SplObserver' => ['spl_ce_SplObserver', self::EXT_SPL_OBSERVER], - 'SplSubject' => ['spl_ce_SplSubject', self::EXT_SPL_OBSERVER], - 'SplObjectStorage' => ['spl_ce_SplObjectStorage', self::EXT_SPL_OBSERVER], - 'MultipleIterator' => ['spl_ce_MultipleIterator', self::EXT_SPL_OBSERVER], - - /** - * Session - */ - 'SessionHandlerInterface' => ['php_session_iface_entry', self::EXT_SESSION], - - /** - * Date - */ - 'DateTimeInterface' => ['php_date_get_interface_ce()', self::EXT_DATE], - 'DateTime' => ['php_date_get_date_ce()', self::EXT_DATE], - 'DateTimeImmutable' => ['php_date_get_immutable_ce()', self::EXT_DATE], - 'DateTimezone' => ['php_date_get_timezone_ce()', self::EXT_DATE], - 'DateInterval' => ['php_date_get_interval_ce()', self::EXT_DATE], - 'DatePeriod' => ['php_date_get_period_ce()', self::EXT_DATE], - - /** - * Closures - */ - 'Closure' => ['zend_ce_closure', 'Zend/zend_closures'], - - /** - * Zend exceptions - */ - 'Throwable' => ['zend_ce_throwable'], - 'Exception' => ['zend_ce_exception'], - 'ErrorException' => ['zend_ce_error_exception'], - 'Error' => ['zend_ce_error'], - 'CompileError' => ['zend_ce_compile_error'], - 'ParseError' => ['zend_ce_parse_error'], - 'TypeError' => ['zend_ce_type_error'], - 'ArgumentCountError' => ['zend_ce_argument_count_error'], - 'ValueError' => ['zend_ce_value_error'], - 'ArithmeticError' => ['zend_ce_arithmetic_error'], - 'DivisionByZeroError' => ['zend_ce_division_by_zero_error'], - 'UnhandledMatchError' => ['zend_ce_unhandled_match_error'], - - /** - * Zend interfaces (Zend/zend_interfaces.h) - */ - 'Traversable' => ['zend_ce_traversable'], - 'IteratorAggregate' => ['zend_ce_aggregate'], - 'Iterator' => ['zend_ce_iterator'], - 'ArrayAccess' => ['zend_ce_arrayaccess'], - 'Serializable' => ['zend_ce_serializable'], - 'Countable' => ['zend_ce_countable'], - 'Stringable' => ['zend_ce_stringable'], - - /** - * PDO - */ - 'PDO' => ['php_pdo_get_dbh_ce()', self::EXT_PDO], - 'PDOException' => ['php_pdo_get_exception()', self::EXT_PDO], - - 'stdClass' => ['zend_standard_class_def'], - ]; + /** + * Loaded via config/class-entries.php + * + * @var array + */ + private array $classEntries; /** * Entry constructor. @@ -193,6 +63,8 @@ public function __construct(string $className, CompilationContext $compilationCo $this->compilationContext = $compilationContext; $this->classname = $this->compilationContext->getFullName($className); + $this->classEntries = require_once __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config/class-entries.php'; + foreach ($this->classEntries as $key => $val) { unset($this->classEntries[$key]); $this->classEntries[strtolower($key)] = $val; diff --git a/config/class-entries.php b/config/class-entries.php new file mode 100644 index 000000000..837819d1a --- /dev/null +++ b/config/class-entries.php @@ -0,0 +1,138 @@ + + * + * For the full copyright and license information, please view + * the LICENSE file that was distributed with this source code. + */ + +declare(strict_types=1); + +/** + * PHP Class Name => [Zend Class Entry, header-file-path (optional)] + */ +return [ + /** + * SPL + */ + 'ArrayObject' => ['spl_ce_ArrayObject', 'ext/spl/spl_array'], + 'ArrayIterator' => ['spl_ce_ArrayIterator', 'ext/spl/spl_array'], + 'RecursiveArrayIterator' => ['spl_ce_RecursiveArrayIterator', 'ext/spl/spl_array'], + + 'SplFileInfo' => ['spl_ce_SplFileInfo', 'ext/spl/spl_directory'], + 'DirectoryIterator' => ['spl_ce_DirectoryIterator', 'ext/spl/spl_directory'], + 'FilesystemIterator' => ['spl_ce_FilesystemIterator', 'ext/spl/spl_directory'], + 'RecursiveDirectoryIterator' => ['spl_ce_RecursiveDirectoryIterator', 'ext/spl/spl_directory'], + 'GlobIterator' => ['spl_ce_GlobIterator', 'ext/spl/spl_directory'], + 'SplFileObject' => ['spl_ce_SplFileObject', 'ext/spl/spl_directory'], + 'SplTempFileObject' => ['spl_ce_SplTempFileObject', 'ext/spl/spl_directory'], + + 'SplDoublyLinkedList' => ['spl_ce_SplDoublyLinkedList', 'ext/spl/spl_dllist'], + 'SplQueue' => ['spl_ce_SplQueue', 'ext/spl/spl_dllist'], + 'SplStack' => ['spl_ce_SplStack', 'ext/spl/spl_dllist'], + + 'LogicException' => ['spl_ce_LogicException', 'ext/spl/spl_exceptions'], + 'BadFunctionCallException' => ['spl_ce_BadFunctionCallException', 'ext/spl/spl_exceptions'], + 'BadMethodCallException' => ['spl_ce_BadMethodCallException', 'ext/spl/spl_exceptions'], + 'DomainException' => ['spl_ce_DomainException', 'ext/spl/spl_exceptions'], + 'InvalidArgumentException' => ['spl_ce_InvalidArgumentException', 'ext/spl/spl_exceptions'], + 'LengthException' => ['spl_ce_LengthException', 'ext/spl/spl_exceptions'], + 'OutOfRangeException' => ['spl_ce_OutOfRangeException', 'ext/spl/spl_exceptions'], + 'RuntimeException' => ['spl_ce_RuntimeException', 'ext/spl/spl_exceptions'], + 'OutOfBoundsException' => ['spl_ce_OutOfBoundsException', 'ext/spl/spl_exceptions'], + 'OverflowException' => ['spl_ce_OverflowException', 'ext/spl/spl_exceptions'], + 'RangeException' => ['spl_ce_RangeException', 'ext/spl/spl_exceptions'], + 'UnderflowException' => ['spl_ce_UnderflowException', 'ext/spl/spl_exceptions'], + 'UnexpectedValueException' => ['spl_ce_UnexpectedValueException', 'ext/spl/spl_exceptions'], + + 'SplFixedArray' => ['spl_ce_SplFixedArray', 'ext/spl/spl_fixedarray'], + + 'SplHeap' => ['spl_ce_SplHeap', 'ext/spl/spl_heap'], + 'SplMinHeap' => ['spl_ce_SplMinHeap', 'ext/spl/spl_heap'], + 'SplMaxHeap' => ['spl_ce_SplMaxHeap', 'ext/spl/spl_heap'], + 'SplPriorityQueue' => ['spl_ce_SplPriorityQueue', 'ext/spl/spl_heap'], + + 'AppendIterator' => ['spl_ce_AppendIterator', 'ext/spl/spl_iterators'], + 'CachingIterator' => ['spl_ce_CachingIterator', 'ext/spl/spl_iterators'], + 'CallbackFilterIterator' => ['spl_ce_CallbackFilterIterator', 'ext/spl/spl_iterators'], + 'EmptyIterator' => ['spl_ce_EmptyIterator', 'ext/spl/spl_iterators'], + 'FilterIterator' => ['spl_ce_FilterIterator', 'ext/spl/spl_iterators'], + 'InfiniteIterator' => ['spl_ce_InfiniteIterator', 'ext/spl/spl_iterators'], + 'IteratorIterator' => ['spl_ce_IteratorIterator', 'ext/spl/spl_iterators'], + 'LimitIterator' => ['spl_ce_LimitIterator', 'ext/spl/spl_iterators'], + 'NoRewindIterator' => ['spl_ce_NoRewindIterator', 'ext/spl/spl_iterators'], + 'OuterIterator' => ['spl_ce_OuterIterator', 'ext/spl/spl_iterators'], + 'ParentIterator' => ['spl_ce_ParentIterator', 'ext/spl/spl_iterators'], + 'RecursiveCachingIterator' => ['spl_ce_RecursiveCachingIterator', 'ext/spl/spl_iterators'], + 'RecursiveCallbackFilterIterator' => ['spl_ce_RecursiveCallbackFilterIterator', 'ext/spl/spl_iterators'], + 'RecursiveFilterIterator' => ['spl_ce_RecursiveFilterIterator', 'ext/spl/spl_iterators'], + 'RecursiveIterator' => ['spl_ce_RecursiveIterator', 'ext/spl/spl_iterators'], + 'RecursiveIteratorIterator' => ['spl_ce_RecursiveIteratorIterator', 'ext/spl/spl_iterators'], + 'RecursiveRegexIterator' => ['spl_ce_RecursiveRegexIterator', 'ext/spl/spl_iterators'], + 'RecursiveTreeIterator' => ['spl_ce_RecursiveTreeIterator', 'ext/spl/spl_iterators'], + 'RegexIterator' => ['spl_ce_RegexIterator', 'ext/spl/spl_iterators'], + 'SeekableIterator' => ['spl_ce_SeekableIterator', 'ext/spl/spl_iterators'], + + 'SplObserver' => ['spl_ce_SplObserver', 'ext/spl/spl_observer'], + 'SplSubject' => ['spl_ce_SplSubject', 'ext/spl/spl_observer'], + 'SplObjectStorage' => ['spl_ce_SplObjectStorage', 'ext/spl/spl_observer'], + 'MultipleIterator' => ['spl_ce_MultipleIterator', 'ext/spl/spl_observer'], + + /** + * Session + */ + 'SessionHandlerInterface' => ['php_session_iface_entry', 'ext/session/php_session'], + + /** + * Date + */ + 'DateTimeInterface' => ['php_date_get_interface_ce()', 'ext/date/php_date'], + 'DateTime' => ['php_date_get_date_ce()', 'ext/date/php_date'], + 'DateTimeImmutable' => ['php_date_get_immutable_ce()', 'ext/date/php_date'], + 'DateTimezone' => ['php_date_get_timezone_ce()', 'ext/date/php_date'], + 'DateInterval' => ['php_date_get_interval_ce()', 'ext/date/php_date'], + 'DatePeriod' => ['php_date_get_period_ce()', 'ext/date/php_date'], + + /** + * Closures + */ + 'Closure' => ['zend_ce_closure', 'Zend/zend_closures'], + + /** + * Zend exceptions + */ + 'Throwable' => ['zend_ce_throwable'], + 'Exception' => ['zend_ce_exception'], + 'ErrorException' => ['zend_ce_error_exception'], + 'Error' => ['zend_ce_error'], + 'CompileError' => ['zend_ce_compile_error'], + 'ParseError' => ['zend_ce_parse_error'], + 'TypeError' => ['zend_ce_type_error'], + 'ArgumentCountError' => ['zend_ce_argument_count_error'], + 'ValueError' => ['zend_ce_value_error'], + 'ArithmeticError' => ['zend_ce_arithmetic_error'], + 'DivisionByZeroError' => ['zend_ce_division_by_zero_error'], + 'UnhandledMatchError' => ['zend_ce_unhandled_match_error'], + + /** + * Zend interfaces (Zend/zend_interfaces.h) + */ + 'Traversable' => ['zend_ce_traversable'], + 'IteratorAggregate' => ['zend_ce_aggregate'], + 'Iterator' => ['zend_ce_iterator'], + 'ArrayAccess' => ['zend_ce_arrayaccess'], + 'Serializable' => ['zend_ce_serializable'], + 'Countable' => ['zend_ce_countable'], + 'Stringable' => ['zend_ce_stringable'], + + /** + * PDO + */ + 'PDO' => ['php_pdo_get_dbh_ce()', 'ext/pdo/php_pdo_driver'], + 'PDOException' => ['php_pdo_get_exception()', 'ext/pdo/php_pdo_driver'], + + 'stdClass' => ['zend_standard_class_def'], +]; From 08fb6a620ffbb697095016e076d3b4784b1c6549 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 11:44:39 +0100 Subject: [PATCH 27/35] #2213 - Fix argument type in `ClassConstant` constructor --- Library/ClassConstant.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Library/ClassConstant.php b/Library/ClassConstant.php index 4d49ad936..a86dddefa 100644 --- a/Library/ClassConstant.php +++ b/Library/ClassConstant.php @@ -33,18 +33,18 @@ class ClassConstant protected array $value = []; /** - * @var string + * @var string|null */ - protected string $docblock; + protected ?string $docblock = null; /** * ClassConstant constructor. * * @param string $name * @param array $value - * @param string $docBlock + * @param string|null $docBlock */ - public function __construct(string $name, array $value, string $docBlock) + public function __construct(string $name, array $value, ?string $docBlock = null) { $this->name = $name; $this->value = $value; From a9ce20fe5ff0a08d267b09653d8cf683596a6adb Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 11:49:49 +0100 Subject: [PATCH 28/35] #2213 - Fix return type of `getDocBlock()` method --- Library/ClassConstant.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/ClassConstant.php b/Library/ClassConstant.php index a86dddefa..29e7250b0 100644 --- a/Library/ClassConstant.php +++ b/Library/ClassConstant.php @@ -100,9 +100,9 @@ public function getValueValue() /** * Returns the docblock related to the constant. * - * @return string + * @return string|null */ - public function getDocBlock(): string + public function getDocBlock(): ?string { return $this->docblock; } From 6fe55d9d1fd59a305a471fc369c8726ce7bb6f53 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 11:57:17 +0100 Subject: [PATCH 29/35] #2213 - Fix require --- Library/Classes/Entry.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Classes/Entry.php b/Library/Classes/Entry.php index b27996040..d477901ea 100644 --- a/Library/Classes/Entry.php +++ b/Library/Classes/Entry.php @@ -63,7 +63,7 @@ public function __construct(string $className, CompilationContext $compilationCo $this->compilationContext = $compilationContext; $this->classname = $this->compilationContext->getFullName($className); - $this->classEntries = require_once __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config/class-entries.php'; + $this->classEntries = require __DIR__.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'config/class-entries.php'; foreach ($this->classEntries as $key => $val) { unset($this->classEntries[$key]); From 6084cf2cf2f77133cd56d00b20170a5b90d6505a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 12:06:51 +0100 Subject: [PATCH 30/35] #2213 - Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 10d581552..ba5de72ad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org). ## [Unreleased] ### Fixed - Fixed nullable dynamic argument definition [#2245](https://github.com/zephir-lang/zephir/issues/2245) +- Changed detection of external class entries [#2213](https://github.com/zephir-lang/zephir/issues/2213) ## [0.13.5] - 2021-05-09 ### Fixed From 08624198fca781eed6b01b96162188cf2085eb0b Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 18:08:21 +0100 Subject: [PATCH 31/35] #2213 - Mass types refactor --- Library/Call.php | 125 ++++++----- Library/ClassConstant.php | 10 +- Library/ClassDefinition.php | 4 +- Library/ClassMethod.php | 2 +- Library/CodePrinter.php | 47 ++-- Library/CompiledExpression.php | 38 ++-- Library/Compiler.php | 204 +++++++++++------- Library/CompilerFile.php | 10 +- Library/Operators/Other/CastOperator.php | 4 +- Library/Operators/Other/CloneOperator.php | 14 +- Library/Operators/Other/ConcatOperator.php | 14 +- Library/Operators/Other/EmptyOperator.php | 10 +- Library/Operators/Other/FetchOperator.php | 22 +- Library/Operators/Other/IssetOperator.php | 10 +- Library/Operators/Other/LikelyOperator.php | 14 +- .../Operators/Other/NewInstanceOperator.php | 8 +- .../Other/NewInstanceTypeOperator.php | 2 + .../Other/RangeExclusiveOperator.php | 10 +- .../Other/RangeInclusiveOperator.php | 10 +- Library/Operators/Other/RequireOperator.php | 15 +- .../Operators/Other/ShortTernaryOperator.php | 10 +- Library/Operators/Other/TernaryOperator.php | 6 +- Library/Operators/Other/TypeHintOperator.php | 10 +- Library/Operators/Other/TypeOfOperator.php | 10 +- Library/Operators/Other/UnlikelyOperator.php | 11 +- 25 files changed, 354 insertions(+), 266 deletions(-) diff --git a/Library/Call.php b/Library/Call.php index 0c6932fff..95662f1af 100644 --- a/Library/Call.php +++ b/Library/Call.php @@ -24,27 +24,54 @@ class Call /** * Call expression. * - * @var Expression + * @var Expression|null */ - protected $expression; + protected ?Expression $expression = null; - protected $mustInit; + /** + * @var bool + */ + protected bool $mustInit = false; - protected $symbolVariable; + /** + * @var Variable|null + */ + protected ?Variable $symbolVariable = null; - protected $isExpecting = false; + /** + * @var bool + */ + protected bool $isExpecting = false; - protected $resolvedParams; + /** + * @var array + */ + protected array $resolvedParams = []; - protected $reflection; + /** + * @var mixed|null + */ + protected $reflection = null; - protected $resolvedTypes = []; + /** + * @var array + */ + protected array $resolvedTypes = []; - protected $resolvedDynamicTypes = []; + /** + * @var array + */ + protected array $resolvedDynamicTypes = []; - protected $temporalVariables = []; + /** + * @var array + */ + protected array $temporalVariables = []; - protected $mustCheckForCopy = []; + /** + * @var array + */ + protected array $mustCheckForCopy = []; /** * Processes the symbol variable that will be used to return @@ -60,7 +87,6 @@ public function processExpectedReturn(CompilationContext $compilationContext) /** * Create temporary variable if needed. */ - $mustInit = false; $symbolVariable = null; $isExpecting = $expr->isExpectingReturn(); if ($isExpecting) { @@ -74,14 +100,13 @@ public function processExpectedReturn(CompilationContext $compilationContext) $expression ); } else { - $mustInit = true; + $this->mustInit = true; } } else { $symbolVariable = $compilationContext->symbolTable->getTempVariableForWrite('variable', $compilationContext, $expression); } } - $this->mustInit = $mustInit; $this->symbolVariable = $symbolVariable; $this->isExpecting = $isExpecting; } @@ -92,7 +117,7 @@ public function processExpectedReturn(CompilationContext $compilationContext) * * @param CompilationContext $compilationContext */ - public function processExpectedObservedReturn(CompilationContext $compilationContext) + public function processExpectedObservedReturn(CompilationContext $compilationContext): void { $expr = $this->expression; $expression = $expr->getExpression(); @@ -127,7 +152,7 @@ public function processExpectedObservedReturn(CompilationContext $compilationCon * * @return bool */ - public function isExpectingReturn() + public function isExpectingReturn(): bool { return $this->isExpecting; } @@ -137,7 +162,7 @@ public function isExpectingReturn() * * @return bool */ - public function mustInitSymbolVariable() + public function mustInitSymbolVariable(): bool { return $this->mustInit; } @@ -145,12 +170,12 @@ public function mustInitSymbolVariable() /** * Returns the symbol variable that must be returned by the call. * - * @param bool $useTemp + * @param bool $useTemp * @param CompilationContext|null $compilationContext * - * @return Variable + * @return Variable|null */ - public function getSymbolVariable($useTemp = false, CompilationContext $compilationContext = null) + public function getSymbolVariable(bool $useTemp = false, CompilationContext $compilationContext = null): ?Variable { $symbolVariable = $this->symbolVariable; @@ -164,17 +189,15 @@ public function getSymbolVariable($useTemp = false, CompilationContext $compilat /** * Resolves parameters. * - * @param array $parameters + * @param array $parameters * @param CompilationContext $compilationContext - * @param array $expression - * @param bool $readOnly + * @param array $expression + * @param bool $readOnly * - * @throws CompilerException - * - * @return array|CompiledExpression[]|null - * @return array + * @return CompiledExpression[]|null + * @throws Exception */ - public function getResolvedParamsAsExpr($parameters, CompilationContext $compilationContext, $expression, $readOnly = false) + public function getResolvedParamsAsExpr(array $parameters, CompilationContext $compilationContext, array $expression, bool $readOnly = false): ?array { if (!$this->resolvedParams) { $hasParametersByName = false; @@ -185,7 +208,7 @@ public function getResolvedParamsAsExpr($parameters, CompilationContext $compila } } - /* + /** * All parameters must be passed by name */ if ($hasParametersByName) { @@ -262,16 +285,15 @@ public function getResolvedParamsAsExpr($parameters, CompilationContext $compila * Resolve parameters getting aware that the target function/method could retain or change * the parameters. * - * @param array $parameters + * @param array $parameters * @param CompilationContext $compilationContext - * @param array $expression - * @param array $calleeDefinition - * - * @throws CompilerException + * @param array $expression + * @param null $calleeDefinition * * @return array + * @throws Exception */ - public function getResolvedParams($parameters, CompilationContext $compilationContext, array $expression, $calleeDefinition = null) + public function getResolvedParams(array $parameters, CompilationContext $compilationContext, array $expression, $calleeDefinition = null): array { $codePrinter = $compilationContext->codePrinter; $exprParams = $this->getResolvedParamsAsExpr($parameters, $compilationContext, $expression); @@ -283,7 +305,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo $readOnlyParameters = []; if (\is_object($calleeDefinition)) { if ($calleeDefinition instanceof ClassMethod) { - if ($calleeDefinition->isFinal() || $calleeDefinition->isPrivate() || $calleeDefinition->isInternal() || $compilationContext->currentMethod == $calleeDefinition) { + if ($calleeDefinition->isFinal() || $calleeDefinition->isPrivate() || $calleeDefinition->isInternal() || $compilationContext->currentMethod === $calleeDefinition) { foreach ($calleeDefinition->getParameters() as $position => $parameter) { if (isset($parameter['data-type'])) { switch ($parameter['data-type']) { @@ -308,7 +330,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo $types = []; $dynamicTypes = []; $mustCheck = []; - foreach ($exprParams as $position => $compiledExpression) { + foreach ($exprParams as $compiledExpression) { $expression = $compiledExpression->getOriginal(); switch ($compiledExpression->getType()) { case 'null': @@ -363,8 +385,7 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo $compilationContext->backend->assignString( $parameterVariable, add_slashes($compiledExpression->getCode()), - $compilationContext, - true + $compilationContext ); $this->temporalVariables[] = $parameterVariable; @@ -463,15 +484,14 @@ public function getResolvedParams($parameters, CompilationContext $compilationCo /** * Resolve parameters using zvals in the stack and without allocating memory for constants. * - * @param array $parameters + * @param array $parameters * @param CompilationContext $compilationContext - * @param array $expression - * - * @throws CompilerException + * @param array $expression * * @return array + * @throws Exception */ - public function getReadOnlyResolvedParams($parameters, CompilationContext $compilationContext, array $expression) + public function getReadOnlyResolvedParams(array $parameters, CompilationContext $compilationContext, array $expression): array { $codePrinter = $compilationContext->codePrinter; $exprParams = $this->getResolvedParamsAsExpr($parameters, $compilationContext, $expression, true); @@ -514,8 +534,7 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi $compilationContext->backend->assignString( $parameterVariable, add_slashes($compiledExpression->getCode()), - $compilationContext, - true + $compilationContext ); $this->temporalVariables[] = $parameterVariable; @@ -645,7 +664,7 @@ public function getReadOnlyResolvedParams($parameters, CompilationContext $compi * * @param CompilationContext $compilationContext */ - public function addCallStatusFlag(CompilationContext $compilationContext) + public function addCallStatusFlag(CompilationContext $compilationContext): void { if (!$compilationContext->symbolTable->hasVariable('ZEPHIR_LAST_CALL_STATUS')) { $callStatus = new Variable('int', 'ZEPHIR_LAST_CALL_STATUS', $compilationContext->branchManager->getCurrentBranch()); @@ -661,7 +680,7 @@ public function addCallStatusFlag(CompilationContext $compilationContext) * * @param CompilationContext $compilationContext */ - public function addCallStatusOrJump(CompilationContext $compilationContext) + public function addCallStatusOrJump(CompilationContext $compilationContext): void { $compilationContext->headersManager->add('kernel/fcall'); if ($compilationContext->insideTryCatch) { @@ -680,7 +699,7 @@ public function addCallStatusOrJump(CompilationContext $compilationContext) * * @param CompilationContext $compilationContext */ - public function checkTempParameters(CompilationContext $compilationContext) + public function checkTempParameters(CompilationContext $compilationContext): void { $compilationContext->headersManager->add('kernel/fcall'); foreach ($this->getMustCheckForCopyVariables() as $checkVariable) { @@ -693,7 +712,7 @@ public function checkTempParameters(CompilationContext $compilationContext) * * @return array */ - public function getResolvedTypes() + public function getResolvedTypes(): array { return $this->resolvedTypes; } @@ -703,7 +722,7 @@ public function getResolvedTypes() * * @return array */ - public function getResolvedDynamicTypes() + public function getResolvedDynamicTypes(): array { return $this->resolvedDynamicTypes; } @@ -713,7 +732,7 @@ public function getResolvedDynamicTypes() * * @return Variable[] */ - public function getTemporalVariables() + public function getTemporalVariables(): array { return $this->temporalVariables; } @@ -723,7 +742,7 @@ public function getTemporalVariables() * * @return array */ - public function getMustCheckForCopyVariables() + public function getMustCheckForCopyVariables(): array { return $this->mustCheckForCopy; } diff --git a/Library/ClassConstant.php b/Library/ClassConstant.php index 29e7250b0..376d50aa3 100644 --- a/Library/ClassConstant.php +++ b/Library/ClassConstant.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir; use Zephir\Exception\CompilerException; @@ -90,11 +92,7 @@ public function getValueType(): string */ public function getValueValue() { - if (isset($this->value['value'])) { - return $this->value['value']; - } - - return false; + return $this->value['value'] ?? false; } /** @@ -157,7 +155,7 @@ public function processValue(CompilationContext $compilationContext) * @throws CompilerException * @throws Exception */ - public function compile(CompilationContext $compilationContext) + public function compile(CompilationContext $compilationContext): void { $this->processValue($compilationContext); diff --git a/Library/ClassDefinition.php b/Library/ClassDefinition.php index 9a84c6643..ad421be22 100644 --- a/Library/ClassDefinition.php +++ b/Library/ClassDefinition.php @@ -1147,7 +1147,7 @@ public function compile(CompilationContext $compilationContext): void foreach ($this->getProperties() as $property) { $docBlock = $property->getDocBlock(); if ($docBlock) { - $codePrinter->outputDocBlock($docBlock, true); + $codePrinter->outputDocBlock($docBlock); } $property->compile($compilationContext); @@ -1165,7 +1165,7 @@ public function compile(CompilationContext $compilationContext): void foreach ($this->getConstants() as $constant) { $docBlock = $constant->getDocBlock(); if ($docBlock) { - $codePrinter->outputDocBlock($docBlock, true); + $codePrinter->outputDocBlock($docBlock); } $constant->compile($compilationContext); diff --git a/Library/ClassMethod.php b/Library/ClassMethod.php index cbd4bac05..2973b13bd 100644 --- a/Library/ClassMethod.php +++ b/Library/ClassMethod.php @@ -750,7 +750,7 @@ public function getInternalParameters(): string return ''; } - return (string)$this->parameters->count().', ...'; + return $this->parameters->count() .', ...'; } /** diff --git a/Library/CodePrinter.php b/Library/CodePrinter.php index 34ab1fad4..35bb839a4 100644 --- a/Library/CodePrinter.php +++ b/Library/CodePrinter.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir; /** @@ -18,20 +20,20 @@ */ class CodePrinter { - protected $code; + protected string $code = ''; - protected $lastLine; + protected string $lastLine = ''; - protected $level = 0; + protected int $level = 0; - protected $currentPrints = 0; + protected int $currentPrints = 0; /** * Adds a line to the output without the automatic line feed. * * @param string $code */ - public function outputNoLineFeed($code) + public function outputNoLineFeed(string $code): void { $this->lastLine = $code; $this->code .= str_repeat("\t", $this->level).$code; @@ -42,7 +44,7 @@ public function outputNoLineFeed($code) * * @param string $code */ - public function preOutput($code) + public function preOutput(string $code): void { $this->lastLine = $code; $this->code = str_repeat("\t", $this->level).$code.PHP_EOL.$this->code; @@ -54,7 +56,7 @@ public function preOutput($code) * * @param string $code */ - public function preOutputNoLineFeed($code) + public function preOutputNoLineFeed(string $code): void { $this->lastLine = $code; $this->code = str_repeat("\t", $this->level).$code.$this->code; @@ -65,7 +67,7 @@ public function preOutputNoLineFeed($code) * * @param string $code */ - public function preOutputNoLevel($code) + public function preOutputNoLevel(string $code): void { $this->lastLine = $code; $this->code = $code.PHP_EOL.$this->code; @@ -77,7 +79,7 @@ public function preOutputNoLevel($code) * * @param string $code */ - public function outputNoIndent($code) + public function outputNoIndent(string $code): void { $this->lastLine = $code; $this->code .= $code.PHP_EOL; @@ -88,6 +90,7 @@ public function outputNoIndent($code) * Add code to the output. * * @param string $code + * @param bool $appendEOL */ public function output(string $code, bool $appendEOL = true): void { @@ -102,7 +105,7 @@ public function output(string $code, bool $appendEOL = true): void * @param $docblock * @param bool $replaceTab */ - public function outputDocBlock($docblock, $replaceTab = true) + public function outputDocBlock($docblock, bool $replaceTab = true): void { $code = ''; $docblock = '/'.$docblock.'/'; @@ -125,7 +128,7 @@ public function outputDocBlock($docblock, $replaceTab = true) * * @param string $code */ - public function outputNoLevel($code) + public function outputNoLevel(string $code): void { $this->lastLine = $code; $this->code .= $code.PHP_EOL; @@ -139,7 +142,7 @@ public function outputNoLevel($code) * * @param bool $ifPrevNotBlank */ - public function preOutputBlankLine($ifPrevNotBlank = false) + public function preOutputBlankLine(bool $ifPrevNotBlank = false): void { if (!$ifPrevNotBlank) { $this->code = PHP_EOL.$this->code; @@ -161,7 +164,7 @@ public function preOutputBlankLine($ifPrevNotBlank = false) * * @param bool $ifPrevNotBlank */ - public function outputBlankLine($ifPrevNotBlank = false) + public function outputBlankLine(bool $ifPrevNotBlank = false): void { if (!$ifPrevNotBlank) { $this->code .= PHP_EOL; @@ -179,7 +182,7 @@ public function outputBlankLine($ifPrevNotBlank = false) /** * Increase the indentation level. */ - public function increaseLevel() + public function increaseLevel(): void { ++$this->level; } @@ -187,12 +190,12 @@ public function increaseLevel() /** * Decrease the indentation level. */ - public function decreaseLevel() + public function decreaseLevel(): void { --$this->level; } - public function setLevel($level) + public function setLevel(int $level): void { $this->level = $level; } @@ -204,7 +207,7 @@ public function setLevel($level) */ public function getOutput(): string { - return (string) $this->code; + return $this->code; } /** @@ -212,7 +215,7 @@ public function getOutput(): string * * @return int */ - public function getNumberPrints() + public function getNumberPrints(): int { return $this->currentPrints; } @@ -220,14 +223,14 @@ public function getNumberPrints() /** * Frees memory used within the code. */ - public function clear() + public function clear(): void { - $this->code = null; - $this->lastLine = null; + $this->code = ''; + $this->lastLine = ''; $this->level = 0; } - public function duplicate() + public function duplicate(): CodePrinter { $printer = new self(); $printer->setLevel($this->level); diff --git a/Library/CompiledExpression.php b/Library/CompiledExpression.php index 62c5e947c..913623010 100644 --- a/Library/CompiledExpression.php +++ b/Library/CompiledExpression.php @@ -9,8 +9,12 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir; +use Closure; + /** * CompiledExpression. * @@ -19,18 +23,18 @@ */ class CompiledExpression implements TypeAwareInterface { - protected $type; + protected string $type; - protected $code; + protected ?string $code; - protected $originalExpr; + protected ?array $originalExpr; /** * @param string $type - * @param string $code - * @param array $originalExpr + * @param string|null $code + * @param array|null $originalExpr */ - public function __construct($type, $code, $originalExpr) + public function __construct(string $type, ?string $code, ?array $originalExpr = null) { $this->type = $type; $this->code = $code; @@ -42,7 +46,7 @@ public function __construct($type, $code, $originalExpr) * * @return string */ - public function getType() + public function getType(): string { return $this->type; } @@ -50,9 +54,9 @@ public function getType() /** * Returns the code produced by the compiled expression. * - * @return string + * @return string|null */ - public function getCode() + public function getCode(): ?string { return $this->code; } @@ -60,9 +64,9 @@ public function getCode() /** * Original AST code that produced the code. * - * @return array + * @return array|null */ - public function getOriginal() + public function getOriginal(): ?array { return $this->originalExpr; } @@ -72,7 +76,7 @@ public function getOriginal() * * @return string */ - public function getBooleanCode() + public function getBooleanCode(): string { if ($this->code && ('true' == $this->code || true === $this->code)) { return '1'; @@ -90,7 +94,7 @@ public function getBooleanCode() * * @return bool */ - public function isIntCompatibleType() + public function isIntCompatibleType(): bool { switch ($this->type) { case 'int': @@ -110,7 +114,7 @@ public function isIntCompatibleType() * * @return bool */ - public function isCharCompatibleType() + public function isCharCompatibleType(): bool { switch ($this->type) { case 'char': @@ -127,14 +131,14 @@ public function isCharCompatibleType() * because it's missing some bound parts, this method resolves the missing parts * returning the generated code. * - * @param string $result + * @param string|null $result * @param CompilationContext $compilationContext * * @return string */ - public function resolve($result, CompilationContext $compilationContext) + public function resolve(?string $result, CompilationContext $compilationContext): string { - if ($this->code instanceof \Closure) { + if ($this->code instanceof Closure) { $code = $this->code; if (!$result) { $tempVariable = $compilationContext->symbolTable->getTempVariableForWrite( diff --git a/Library/Compiler.php b/Library/Compiler.php index 4e4e8d051..498aca6ce 100644 --- a/Library/Compiler.php +++ b/Library/Compiler.php @@ -13,6 +13,7 @@ use Psr\Log\LoggerAwareTrait; use Psr\Log\NullLogger; +use ReflectionException; use Zephir\Code\Builder\Struct; use Zephir\Compiler\CompilerFileFactory; use Zephir\Exception\CompilerException; @@ -33,17 +34,25 @@ final class Compiler { use LoggerAwareTrait; - /** @var BaseBackend */ - public $backend; + /** + * @var BaseBackend + */ + public BaseBackend $backend; - /** @var FunctionDefinition[] */ - public $functionDefinitions = []; + /** + * @var FunctionDefinition[] + */ + public array $functionDefinitions = []; - /** @var CompilerFile[] */ - private $files = []; + /** + * @var CompilerFile[] + */ + private array $files = []; - /** @var string[] */ - private $anonymousFiles = []; + /** + * @var string[] + */ + private array $anonymousFiles = []; /** * Additional initializer code. @@ -51,53 +60,83 @@ final class Compiler * * @var array */ - private $internalInitializers = []; + private array $internalInitializers = []; - /** @var ClassDefinition[] */ - private $definitions = []; + /** + * @var ClassDefinition[] + */ + private array $definitions = []; - /** @var string[] */ - private $compiledFiles = []; + /** + * @var string[] + */ + private array $compiledFiles = []; - private $constants = []; + private array $constants = []; - private $globals = []; + private array $globals = []; - private $externalDependencies = []; + private array $externalDependencies = []; - /** @var ClassDefinition[] */ - private static $internalDefinitions = []; + /** + * @var ClassDefinition[] + */ + private static array $internalDefinitions = []; - private static $loadedPrototypes = false; + /** + * @var bool + */ + private static bool $loadedPrototypes = false; - private $extraFiles = []; + /** + * @var array + */ + private array $extraFiles = []; - /** @var Config */ - private $config; + /** + * @var Config + */ + private Config $config; - /** @var Parser\Manager */ - private $parserManager; + /** + * @var Parser\Manager + */ + private Parser\Manager $parserManager; - /** @var StringsManager */ - private $stringManager; + /** + * @var StringsManager + */ + private StringsManager $stringManager; - /** @var FcallManagerInterface */ - private $fcallManager; + /** + * @var FcallManagerInterface + */ + private FcallManagerInterface $fcallManager; - /** @var string|null */ - private $prototypesPath; + /** + * @var string|null + */ + private ?string $prototypesPath; - /** @var string|null */ - private $optimizersPath; + /** + * @var string|null + */ + private ?string $optimizersPath; - /** @var string|null */ - private $templatesPath; + /** + * @var string|null + */ + private ?string $templatesPath; - /** @var FileSystemInterface */ - private $filesystem; + /** + * @var FileSystemInterface + */ + private FileSystemInterface $filesystem; - /** @var CompilerFileFactory */ - private $compilerFileFactory; + /** + * @var CompilerFileFactory + */ + private CompilerFileFactory $compilerFileFactory; /** * Compiler constructor. @@ -138,7 +177,7 @@ public function __construct( /** * @param string $prototypesPath */ - public function setPrototypesPath($prototypesPath) + public function setPrototypesPath(string $prototypesPath): void { $this->prototypesPath = $prototypesPath; } @@ -150,7 +189,7 @@ public function setPrototypesPath($prototypesPath) * * @throws IllegalStateException in case of absence internal prototypes directory */ - private function resolvePrototypesPath() + private function resolvePrototypesPath(): ?string { $prototypesPath = $this->prototypesPath; @@ -169,7 +208,7 @@ private function resolvePrototypesPath() /** * @param string $optimizersPath */ - public function setOptimizersPath($optimizersPath) + public function setOptimizersPath(string $optimizersPath): void { $this->optimizersPath = $optimizersPath; } @@ -181,7 +220,7 @@ public function setOptimizersPath($optimizersPath) * * @throws IllegalStateException in case of absence internal optimizers directory */ - private function resolveOptimizersPath() + private function resolveOptimizersPath(): ?string { $optimizersPath = $this->optimizersPath; @@ -212,7 +251,7 @@ public function setTemplatesPath(string $templatesPath): void * * @return Parser\Manager */ - public function getParserManager() + public function getParserManager(): Parser\Manager { return $this->parserManager; } @@ -251,7 +290,7 @@ public function addFunction(FunctionDefinition $func, $statement = null) * @throws IllegalStateException * @throws ParseException */ - public function loadExternalClass($className, $location) + public function loadExternalClass(string $className, string $location): bool { $filePath = $location.\DIRECTORY_SEPARATOR. strtolower(str_replace('\\', \DIRECTORY_SEPARATOR, $className)).'.zep'; @@ -287,7 +326,7 @@ public function loadExternalClass($className, $location) * * @return bool */ - public function isClass($className) + public function isClass(string $className): bool { foreach ($this->definitions as $key => $value) { if (!strcasecmp($key, $className) && 'class' === $value->getType()) { @@ -295,14 +334,12 @@ public function isClass($className) } } - /* + /** * Try to autoload the class from an external dependency */ - if (count($this->externalDependencies)) { - foreach ($this->externalDependencies as $namespace => $location) { - if (preg_match('#^'.$namespace.'\\\\#i', $className)) { - return $this->loadExternalClass($className, $location); - } + foreach ($this->externalDependencies as $namespace => $location) { + if (preg_match('#^'.$namespace.'\\\\#i', $className)) { + return $this->loadExternalClass($className, $location); } } @@ -320,7 +357,7 @@ public function isClass($className) * @throws IllegalStateException * @throws ParseException */ - public function isInterface($className) + public function isInterface(string $className): bool { foreach ($this->definitions as $key => $value) { if (!strcasecmp($key, $className) && 'interface' === $value->getType()) { @@ -328,14 +365,12 @@ public function isInterface($className) } } - /* + /** * Try to autoload the class from an external dependency */ - if (count($this->externalDependencies)) { - foreach ($this->externalDependencies as $namespace => $location) { - if (preg_match('#^'.$namespace.'\\\\#i', $className)) { - return $this->loadExternalClass($className, $location); - } + foreach ($this->externalDependencies as $namespace => $location) { + if (preg_match('#^'.$namespace.'\\\\#i', $className)) { + return $this->loadExternalClass($className, $location); } } @@ -349,7 +384,7 @@ public function isInterface($className) * * @return bool */ - public function isBundledClass($className) + public function isBundledClass(string $className): bool { return class_exists($className, false); } @@ -361,7 +396,7 @@ public function isBundledClass($className) * * @return bool */ - public function isBundledInterface($className) + public function isBundledInterface(string $className): bool { return interface_exists($className, false); } @@ -373,7 +408,7 @@ public function isBundledInterface($className) * * @return ClassDefinition|false returns false if no class definition is found */ - public function getClassDefinition($className) + public function getClassDefinition(string $className) { foreach ($this->definitions as $key => $value) { if (!strcasecmp($key, $className)) { @@ -403,9 +438,9 @@ public function addClassDefinition(CompilerFileAnonymous $file, ClassDefinition * * @return ClassDefinition * - * @throws \ReflectionException + * @throws ReflectionException */ - public function getInternalClassDefinition($className) + public function getInternalClassDefinition(string $className): ClassDefinition { if (!isset(self::$internalDefinitions[$className])) { $reflection = new \ReflectionClass($className); @@ -422,7 +457,7 @@ public function getInternalClassDefinition($className) * * @return bool */ - public function isConstant($name) + public function isConstant(string $name): bool { return isset($this->constants[$name]); } @@ -431,8 +466,9 @@ public function isConstant($name) * Returns a Zephir Constant by its name. * * @param string $name + * @return mixed */ - public function getConstant($name) + public function getConstant(string $name) { return $this->constants[$name]; } @@ -456,7 +492,7 @@ public function setExtensionGlobals(array $globals) * * @return bool */ - public function isExtensionGlobal($name) + public function isExtensionGlobal(string $name): bool { return isset($this->globals[$name]); } @@ -468,7 +504,7 @@ public function isExtensionGlobal($name) * * @return array */ - public function getExtensionGlobal($name) + public function getExtensionGlobal(string $name): array { return $this->globals[$name]; } @@ -480,7 +516,7 @@ public function getExtensionGlobal($name) * * @return string */ - public function getGccFlags($development = false) + public function getGccFlags(bool $development = false): string { if (is_windows()) { // TODO @@ -510,7 +546,7 @@ public function getGccFlags($development = false) * * @return string */ - public function getPhpIncludeDirs() + public function getPhpIncludeDirs(): string { $this->filesystem->system('php-config --includes', 'stdout', 'php-includes'); @@ -1836,12 +1872,12 @@ public function createProjectFiles($project) return $needConfigure; } - public function generateFunctionInformation() + public function generateFunctionInformation(): array { $headerPrinter = new CodePrinter(); $entryPrinter = new CodePrinter(); - /* + /** * Specifying Argument Information */ foreach ($this->functionDefinitions as $func) { @@ -1974,8 +2010,8 @@ public function generatePackageDependenciesM4($contentM4) $pkgconfigM4 .= $pkgM4Buf; $extraCFlags .= '$PHP_'.strtoupper($pkg).'_INCS '; } - $contentM4 = str_replace('%PROJECT_EXTRA_CFLAGS%', '%PROJECT_EXTRA_CFLAGS% '.$extraCFlags, $contentM4); + $contentM4 = str_replace('%PROJECT_EXTRA_CFLAGS%', '%PROJECT_EXTRA_CFLAGS% '.$extraCFlags, $contentM4); $contentM4 = str_replace('%PROJECT_PACKAGE_DEPENDENCIES%', $pkgconfigM4, $contentM4); return $contentM4; @@ -1993,7 +2029,7 @@ public function generatePackageDependenciesM4($contentM4) * * @throws IllegalStateException */ - private function preCompile($filePath) + private function preCompile(string $filePath) { if (!$this->parserManager->isAvailable()) { throw new IllegalStateException($this->parserManager->requirements()); @@ -2021,7 +2057,7 @@ private function preCompile($filePath) * @throws IllegalStateException * @throws InvalidArgumentException */ - private function recursivePreCompile($path) + private function recursivePreCompile(string $path) { if (!is_dir($path)) { throw new InvalidArgumentException( @@ -2034,7 +2070,7 @@ private function recursivePreCompile($path) ); } - /* + /** * Pre compile all files. */ $iterator = new \RecursiveIteratorIterator( @@ -2133,7 +2169,7 @@ private function recursiveDeletePath($path, $mask) * * @throws Exception */ - private function loadConstantsSources($constantsSources) + private function loadConstantsSources(array $constantsSources) { foreach ($constantsSources as $constantsSource) { if (!file_exists($constantsSource)) { @@ -2155,12 +2191,12 @@ private function loadConstantsSources($constantsSources) /** * Process config.w32 sections. * - * @param array $sources + * @param array $sources * @param string $project * * @return array */ - private function processAddSources($sources, $project) + private function processAddSources(array $sources, string $project): array { $groupSources = []; foreach ($sources as $source) { @@ -2168,8 +2204,10 @@ private function processAddSources($sources, $project) if (!isset($groupSources[$dirName])) { $groupSources[$dirName] = []; } + $groupSources[$dirName][] = basename($source); } + $groups = []; foreach ($groupSources as $dirname => $files) { $groups[] = 'ADD_SOURCES(configure_module_dirname + "/'.$dirname.'", "'. @@ -2221,7 +2259,7 @@ private function assertRequiredExtensionsIsPresent() * * @return bool */ - private function checkKernelFile($src, $dst) + private function checkKernelFile(string $src, string $dst): bool { if (preg_match('#kernels/ZendEngine[2-9]/concat\.#', $src)) { return true; @@ -2231,7 +2269,7 @@ private function checkKernelFile($src, $dst) return false; } - return md5_file($src) == md5_file($dst); + return md5_file($src) === md5_file($dst); } /** @@ -2241,7 +2279,7 @@ private function checkKernelFile($src, $dst) * * @return bool */ - private function checkKernelFiles() + private function checkKernelFiles(): bool { $kernelPath = 'ext'.\DIRECTORY_SEPARATOR.'kernel'; @@ -2281,7 +2319,7 @@ private function checkKernelFiles() * * @return string */ - private function checkDirectory() + private function checkDirectory(): string { $namespace = $this->config->get('namespace'); if (!$namespace) { @@ -2316,7 +2354,7 @@ private function checkDirectory() * * @return string */ - private function getGccVersion() + private function getGccVersion(): string { if (is_windows()) { return '0.0.0'; diff --git a/Library/CompilerFile.php b/Library/CompilerFile.php index 7c83ea8a5..29fb76d5e 100644 --- a/Library/CompilerFile.php +++ b/Library/CompilerFile.php @@ -639,7 +639,7 @@ public function preCompile(Compiler $compiler) if (!$class && !$interface) { throw new CompilerException( 'Every file must contain at least a class or an interface', - isset($topStatement) ? $topStatement : null + $topStatement ?? null ); } @@ -1154,7 +1154,7 @@ protected function processShortcuts(array $property, ClassDefinition $classDefin * * @return string */ - protected function getFullName($name) + protected function getFullName(string $name): string { return fqcn($name, $this->namespace, $this->aliasManager); } @@ -1163,11 +1163,11 @@ protected function getFullName($name) * Create returns type list. * * @param array $types - * @param bool $annotated + * @param bool $annotated * * @return array */ - protected function createReturnsType(array $types, $annotated = false) + protected function createReturnsType(array $types, bool $annotated = false): ?array { if (!$types) { return null; @@ -1178,7 +1178,7 @@ protected function createReturnsType(array $types, $annotated = false) foreach ($types as $type) { $list[] = [ 'type' => $annotated ? 'return-type-annotation' : 'return-type-paramater', - 'data-type' => 'mixed' == $type ? 'variable' : $type, + 'data-type' => 'mixed' === $type ? 'variable' : $type, 'mandatory' => false, ]; } diff --git a/Library/Operators/Other/CastOperator.php b/Library/Operators/Other/CastOperator.php index cc5e3a582..c38ab4def 100644 --- a/Library/Operators/Other/CastOperator.php +++ b/Library/Operators/Other/CastOperator.php @@ -53,7 +53,7 @@ public function compile(array $expression, CompilationContext $compilationContex case Types::T_INT: switch ($resolved->getType()) { case Types::T_NULL: - return new CompiledExpression('int', 0, $expression); + return new CompiledExpression('int', '0', $expression); case Types::T_CHAR: case Types::T_UCHAR: @@ -258,7 +258,7 @@ public function compile(array $expression, CompilationContext $compilationContex case Types::T_DOUBLE: switch ($resolved->getType()) { case Types::T_NULL: - return new CompiledExpression('double', 0, $expression); + return new CompiledExpression('double', '0', $expression); case Types::T_BOOL: return new CompiledExpression('double', $resolved->getBooleanCode(), $expression); diff --git a/Library/Operators/Other/CloneOperator.php b/Library/Operators/Other/CloneOperator.php index bd1a678fc..b7a8d6c3c 100644 --- a/Library/Operators/Other/CloneOperator.php +++ b/Library/Operators/Other/CloneOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -25,14 +28,13 @@ class CloneOperator extends BaseOperator { /** - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { $compilationContext->headersManager->add('kernel/object'); @@ -41,12 +43,12 @@ public function compile(array $expression, CompilationContext $compilationContex $exprVariable->setExpectReturn(true); $exprCompiledVariable = $exprVariable->compile($compilationContext); - if ('variable' != $exprCompiledVariable->getType()) { + if ('variable' !== $exprCompiledVariable->getType()) { throw new CompilerException('Expression type: '.$exprCompiledVariable->getType().' cannot be used as array', $expression); } $clonedVariable = $compilationContext->symbolTable->getVariableForRead($exprCompiledVariable->getCode(), $compilationContext, $expression); - if ('variable' != $clonedVariable->getType()) { + if ('variable' !== $clonedVariable->getType()) { throw new CompilerException('Variable type: '.$exprVariable->getType().' cannot be cloned'); } diff --git a/Library/Operators/Other/ConcatOperator.php b/Library/Operators/Other/ConcatOperator.php index bc8a8d4ed..f013848fa 100644 --- a/Library/Operators/Other/ConcatOperator.php +++ b/Library/Operators/Other/ConcatOperator.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use function Zephir\add_slashes; @@ -29,14 +31,14 @@ class ConcatOperator extends BaseOperator /** * Performs concat compilation. * - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * * @return CompiledExpression * * @throws CompilerException */ - public function compile($expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException('Missing left part of the expression', $expression); @@ -108,15 +110,15 @@ public function compile($expression, CompilationContext $compilationContext) } /** - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext - * @param bool $isFullString + * @param bool $isFullString * * @return array * * @throws CompilerException */ - private function _getOptimizedConcat($expression, CompilationContext $compilationContext, &$isFullString) + private function _getOptimizedConcat(array $expression, CompilationContext $compilationContext, &$isFullString): array { $originalExpr = $expression; $isFullString = true; @@ -261,7 +263,7 @@ private function _getOptimizedConcat($expression, CompilationContext $compilatio return [$key, implode(', ', $concatParts)]; } - private function compileExpression(Expression $expression, CompilationContext $context, $type) + private function compileExpression(Expression $expression, CompilationContext $context, $type): CompiledExpression { try { switch ($type) { diff --git a/Library/Operators/Other/EmptyOperator.php b/Library/Operators/Other/EmptyOperator.php index 78f00b138..471b7bdda 100644 --- a/Library/Operators/Other/EmptyOperator.php +++ b/Library/Operators/Other/EmptyOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -25,14 +28,13 @@ class EmptyOperator extends BaseOperator { /** - * @param $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { $compilationContext->headersManager->add('kernel/operators'); diff --git a/Library/Operators/Other/FetchOperator.php b/Library/Operators/Other/FetchOperator.php index bbd6854aa..f44bc8a3e 100644 --- a/Library/Operators/Other/FetchOperator.php +++ b/Library/Operators/Other/FetchOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -26,14 +29,13 @@ class FetchOperator extends BaseOperator { /** - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { $compilationContext->headersManager->add('kernel/array'); @@ -42,11 +44,11 @@ public function compile(array $expression, CompilationContext $compilationContex throw new CompilerException('Cannot use variable type: '.$variable->gettype().' in "fetch" operator', $expression); } - /* + /** * return_value must not be observed */ - if ('return_value' != $variable->getName()) { - /* + if ('return_value' !== $variable->getName()) { + /** * TODO: use a read detector here */ $readOnly = false; @@ -73,11 +75,7 @@ public function compile(array $expression, CompilationContext $compilationContex $variable = $compilationContext->symbolTable->getTempVariableForObserve('variable', $compilationContext); } - if ($readOnly) { - $flags = '1'; - } else { - $flags = '0'; - } + $flags = $readOnly ? '1' : '0'; switch ($expression['right']['type']) { case 'array-access': diff --git a/Library/Operators/Other/IssetOperator.php b/Library/Operators/Other/IssetOperator.php index 1a4a795bc..a260c36ec 100644 --- a/Library/Operators/Other/IssetOperator.php +++ b/Library/Operators/Other/IssetOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -27,14 +30,13 @@ class IssetOperator extends BaseOperator /** * Compiles an 'isset' operator. * - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { if ('list' == $expression['left']['type']) { $left = $expression['left']['left']; diff --git a/Library/Operators/Other/LikelyOperator.php b/Library/Operators/Other/LikelyOperator.php index feac274f7..679b001bb 100644 --- a/Library/Operators/Other/LikelyOperator.php +++ b/Library/Operators/Other/LikelyOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -25,14 +28,13 @@ class LikelyOperator extends BaseOperator { /** - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException("Invalid 'left' operand for 'likely' expression", $expression['left']); @@ -42,11 +44,11 @@ public function compile(array $expression, CompilationContext $compilationContex $leftExpr->setReadOnly(true); $left = $leftExpr->compile($compilationContext); - if ('bool' == $left->getType()) { + if ('bool' === $left->getType()) { return new CompiledExpression('bool', 'EXPECTED('.$left->getCode().')', $expression); } - if ('variable' == $left->getType()) { + if ('variable' === $left->getType()) { $variable = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression['left']); switch ($variable->getType()) { case 'bool': diff --git a/Library/Operators/Other/NewInstanceOperator.php b/Library/Operators/Other/NewInstanceOperator.php index ef4629dcc..7dae34d31 100644 --- a/Library/Operators/Other/NewInstanceOperator.php +++ b/Library/Operators/Other/NewInstanceOperator.php @@ -49,7 +49,7 @@ public function compile(array $expression, CompilationContext $compilationContex { $codePrinter = $compilationContext->codePrinter; - /* + /** * Resolves the symbol that expects the value */ $this->literalOnly = false; @@ -62,7 +62,7 @@ public function compile(array $expression, CompilationContext $compilationContex throw new CompilerException('Cannot use non-heap variable to store new instance', $expression); } - if ('return_value' != $symbolVariable->getName()) { + if ('return_value' !== $symbolVariable->getName()) { if ($symbolVariable->hasDifferentDynamicType(['unknown', 'undefined', 'object', 'null'])) { $compilationContext->logger->warning( 'Possible attempt to use non-object in "new" operator', @@ -71,7 +71,7 @@ public function compile(array $expression, CompilationContext $compilationContex } } - /* + /** * Mark variables as dynamic objects */ $symbolVariable->setDynamicTypes('object'); @@ -236,7 +236,7 @@ public function compile(array $expression, CompilationContext $compilationContex ]); } - /* + /** * If we are certain that there is a constructor we call it, otherwise we checked it at runtime. */ if ($callConstructor) { diff --git a/Library/Operators/Other/NewInstanceTypeOperator.php b/Library/Operators/Other/NewInstanceTypeOperator.php index 3fa30139a..65885e98b 100644 --- a/Library/Operators/Other/NewInstanceTypeOperator.php +++ b/Library/Operators/Other/NewInstanceTypeOperator.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\Builder\FunctionCallBuilder; diff --git a/Library/Operators/Other/RangeExclusiveOperator.php b/Library/Operators/Other/RangeExclusiveOperator.php index be24288e6..c4f5e7bce 100644 --- a/Library/Operators/Other/RangeExclusiveOperator.php +++ b/Library/Operators/Other/RangeExclusiveOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Expression\Builder\BuilderFactory; @@ -26,14 +29,13 @@ class RangeExclusiveOperator extends BaseOperator { /** - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException("Invalid 'left' operand for 'irange' expression", $expression['left']); diff --git a/Library/Operators/Other/RangeInclusiveOperator.php b/Library/Operators/Other/RangeInclusiveOperator.php index 689e107e5..72ad8419b 100644 --- a/Library/Operators/Other/RangeInclusiveOperator.php +++ b/Library/Operators/Other/RangeInclusiveOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -26,14 +29,13 @@ class RangeInclusiveOperator extends BaseOperator { /** - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException("Invalid 'left' operand for 'irange' expression", $expression['left']); diff --git a/Library/Operators/Other/RequireOperator.php b/Library/Operators/Other/RequireOperator.php index 657667856..9103b472a 100644 --- a/Library/Operators/Other/RequireOperator.php +++ b/Library/Operators/Other/RequireOperator.php @@ -9,11 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; -use Zephir\Exception\CompilerException; +use Zephir\Exception; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -25,24 +27,23 @@ class RequireOperator extends BaseOperator { /** - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { $expr = new Expression($expression['left']); $expr->setReadOnly(true); $expr->setExpectReturn(true); $exprPath = $expr->compile($compilationContext); - if ('variable' == $exprPath->getType()) { + if ('variable' === $exprPath->getType()) { $exprVariable = $compilationContext->symbolTable->getVariableForRead($exprPath->getCode(), $compilationContext, $expression); $exprVar = $compilationContext->backend->getVariableCode($exprVariable); - if ('variable' == $exprVariable->getType()) { + if ('variable' === $exprVariable->getType()) { if ($exprVariable->hasDifferentDynamicType(['undefined', 'string'])) { $compilationContext->logger->warning( 'Possible attempt to use invalid type as path in "require" operator', diff --git a/Library/Operators/Other/ShortTernaryOperator.php b/Library/Operators/Other/ShortTernaryOperator.php index 408d080ca..971464969 100644 --- a/Library/Operators/Other/ShortTernaryOperator.php +++ b/Library/Operators/Other/ShortTernaryOperator.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\Builder\Operators\UnaryOperatorBuilder; @@ -37,9 +39,9 @@ class ShortTernaryOperator extends BaseOperator * * @return CompiledExpression */ - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { - /* + /** * This variable is used to check if the compound and expression is evaluated as true or false: * Ensure that newly allocated variables are local-only (setReadOnly) */ @@ -61,7 +63,7 @@ public function compile($expression, CompilationContext $compilationContext) $expression['left'] ), new StatementsBlockBuilder([ - /* + /** * Create an implicit 'let' operation to update the evaluated right operator */ new LetStatementBuilder([ @@ -75,7 +77,7 @@ public function compile($expression, CompilationContext $compilationContext) ], $expression['extra']), ]), new StatementsBlockBuilder([ - /* + /** * Create an implicit 'let' operation to update the evaluated right operator */ new LetStatementBuilder([ diff --git a/Library/Operators/Other/TernaryOperator.php b/Library/Operators/Other/TernaryOperator.php index 799b78ca2..561492aac 100644 --- a/Library/Operators/Other/TernaryOperator.php +++ b/Library/Operators/Other/TernaryOperator.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; @@ -32,9 +34,9 @@ class TernaryOperator extends BaseOperator * * @return CompiledExpression */ - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { - /* + /** * This variable is used to check if the compound and expression is evaluated as true or false: * Ensure that newly allocated variables are local-only (setReadOnly) */ diff --git a/Library/Operators/Other/TypeHintOperator.php b/Library/Operators/Other/TypeHintOperator.php index ef02d6396..b53c37b02 100644 --- a/Library/Operators/Other/TypeHintOperator.php +++ b/Library/Operators/Other/TypeHintOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -37,14 +40,13 @@ public function setStrict($strict) /** * Performs type-hint compilation. * - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { $expr = new Expression($expression['right']); $expr->setReadOnly(true); diff --git a/Library/Operators/Other/TypeOfOperator.php b/Library/Operators/Other/TypeOfOperator.php index 3cb77553f..29120ecfd 100644 --- a/Library/Operators/Other/TypeOfOperator.php +++ b/Library/Operators/Other/TypeOfOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Expression\Builder\BuilderFactory; @@ -29,11 +32,10 @@ class TypeOfOperator extends BaseOperator * @param $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * - * @return bool|CompiledExpression + * @return CompiledExpression + * @throws Exception */ - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException("Invalid 'left' operand for 'typeof' expression", $expression['left']); diff --git a/Library/Operators/Other/UnlikelyOperator.php b/Library/Operators/Other/UnlikelyOperator.php index 87dd58f3b..cdef007d3 100644 --- a/Library/Operators/Other/UnlikelyOperator.php +++ b/Library/Operators/Other/UnlikelyOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Other; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -30,9 +33,9 @@ class UnlikelyOperator extends BaseOperator * @param $expression * @param CompilationContext $compilationContext * @return CompiledExpression - * @throws CompilerException + * @throws Exception */ - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException("Invalid 'left' operand for 'unlikely' expression", $expression['left']); @@ -42,11 +45,11 @@ public function compile($expression, CompilationContext $compilationContext) $leftExpr->setReadOnly(true); $left = $leftExpr->compile($compilationContext); - if ('bool' == $left->getType()) { + if ('bool' === $left->getType()) { return new CompiledExpression('bool', 'UNEXPECTED('.$left->getCode().')', $expression); } - if ('variable' == $left->getType()) { + if ('variable' === $left->getType()) { $variable = $compilationContext->symbolTable->getVariableForRead($left->getCode(), $compilationContext, $expression['left']); switch ($variable->getType()) { case 'bool': From 69fcba5b43d5da06718a4211a5c6b60dd3358ef4 Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 18:32:36 +0100 Subject: [PATCH 32/35] #2213 - Mass types refactor --- Library/Call.php | 2 + .../Logger/Formatter/CompilerFormatter.php | 30 ++++++----- Library/Operators/BaseOperator.php | 25 ++++----- Library/Operators/Logical/AndOperator.php | 17 +++++-- .../Operators/Logical/LogicalBaseOperator.php | 51 ++++--------------- Library/Operators/Logical/OrOperator.php | 11 ++-- Library/Operators/Other/ConcatOperator.php | 6 +-- .../Operators/Other/InstanceOfOperator.php | 2 +- Library/Operators/Other/IssetOperator.php | 2 +- .../Operators/Other/NewInstanceOperator.php | 10 ++-- .../Other/NewInstanceTypeOperator.php | 7 ++- Library/Operators/Unary/MinusOperator.php | 8 +-- Library/Operators/Unary/NotOperator.php | 8 +-- Library/Operators/Unary/PlusOperator.php | 8 +-- 14 files changed, 90 insertions(+), 97 deletions(-) diff --git a/Library/Call.php b/Library/Call.php index 95662f1af..19252a563 100644 --- a/Library/Call.php +++ b/Library/Call.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir; use Zephir\Detectors\ReadDetector; diff --git a/Library/Logger/Formatter/CompilerFormatter.php b/Library/Logger/Formatter/CompilerFormatter.php index 4d61d7a48..34fc1406e 100644 --- a/Library/Logger/Formatter/CompilerFormatter.php +++ b/Library/Logger/Formatter/CompilerFormatter.php @@ -9,29 +9,35 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Logger\Formatter; use Monolog\Formatter\LineFormatter; use Zephir\Config; +use function array_key_exists; +use function count; +use function is_array; + /** * Formatter for warnings/notices/errors generated in compilation. */ final class CompilerFormatter extends LineFormatter { - const SIMPLE_FORMAT = " %level_name%: %message% in %file% on line %line% %type%\n"; + public const SIMPLE_FORMAT = " %level_name%: %message% in %file% on line %line% %type%\n"; /** * @var Config */ - private $config; + private Config $config; /** * The contents of the files that are involved in the log message. * * @var array */ - private $filesContent = []; + private array $filesContent = []; public function __construct(Config $config) { @@ -41,7 +47,8 @@ public function __construct(Config $config) } /** - * {@inheritdoc} + * @param array $record + * @return string */ public function format(array $record): string { @@ -60,8 +67,8 @@ public function format(array $record): string // ignore empty context or invalid format if (!empty($vars['context']) && - \is_array($vars['context']) && - 2 == \count($vars['context']) + is_array($vars['context']) && + 2 == count($vars['context']) ) { $type = $vars['context'][0]; $node = $vars['context'][1]; @@ -70,7 +77,7 @@ public function format(array $record): string return ''; } - $vars['type'] = "[{$type}]"; + $vars['type'] = "[$type]"; if (!isset($node['file'])) { $vars['file'] = 'unknown'; @@ -96,15 +103,14 @@ public function format(array $record): string } $output = $this->replacePlaceholders($vars, $output); - $output = $this->cleanExtraPlaceholders($output); - return $output; + return $this->cleanExtraPlaceholders($output); } private function replacePlaceholders(array $vars, $output) { // WARNING -> Warning - if (\array_key_exists('level_name', $vars)) { + if (array_key_exists('level_name', $vars)) { $vars['level_name'] = ucfirst(strtolower($vars['level_name'])); } @@ -139,7 +145,7 @@ private function replacePlaceholders(array $vars, $output) * * @return string */ - private function cleanExtraPlaceholders($output) + private function cleanExtraPlaceholders(string $output): string { if (false !== strpos($output, '%')) { $output = preg_replace('/%(?:extra|context)\..+?%/', '', $output); @@ -158,7 +164,7 @@ private function cleanExtraPlaceholders($output) * * @return array */ - private function getFileContents($file) + private function getFileContents(string $file): array { if (!isset($this->filesContent[$file])) { $this->filesContent[$file] = file_exists($file) ? file($file) : []; diff --git a/Library/Operators/BaseOperator.php b/Library/Operators/BaseOperator.php index 147d3283c..bd8e96b60 100644 --- a/Library/Operators/BaseOperator.php +++ b/Library/Operators/BaseOperator.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators; use Zephir\CompilationContext; @@ -36,7 +38,7 @@ class BaseOperator * @param bool $expecting * @param Variable|null $expectingVariable */ - public function setExpectReturn(bool $expecting, Variable $expectingVariable = null) + public function setExpectReturn(bool $expecting, ?Variable $expectingVariable = null) { $this->expecting = $expecting; $this->expectingVariable = $expectingVariable; @@ -47,12 +49,12 @@ public function setExpectReturn(bool $expecting, Variable $expectingVariable = n * store the result. This method returns a variable that is always stored in the heap. * * @param CompilationContext $compilationContext - * @param array $expression - * @param bool $init + * @param array $expression + * @param bool $init * * @return Variable */ - public function getExpectedNonLiteral(CompilationContext $compilationContext, $expression, $init = true) + public function getExpectedNonLiteral(CompilationContext $compilationContext, array $expression, bool $init = true): ?Variable { $isExpecting = $this->expecting; $symbolVariable = $this->expectingVariable; @@ -80,19 +82,19 @@ public function getExpectedNonLiteral(CompilationContext $compilationContext, $e * store the result. * * @param CompilationContext $compilationContext - * @param array $expression - * @param bool $init + * @param array $expression + * @param bool $init * * @return Variable */ - public function getExpected(CompilationContext $compilationContext, $expression, $init = true) + public function getExpected(CompilationContext $compilationContext, array $expression, bool $init = true): ?Variable { $isExpecting = $this->expecting; $symbolVariable = $this->expectingVariable; if ($isExpecting) { if (\is_object($symbolVariable)) { - if ('variable' == $symbolVariable->getType()) { + if ('variable' === $symbolVariable->getType()) { if (!$init) { return $symbolVariable; } @@ -130,19 +132,18 @@ public function getExpected(CompilationContext $compilationContext, $expression, * on every iteration. * * @param CompilationContext $compilationContext - * @param array $expression - * @param string $type + * @param string $type * * @return Variable */ - public function getExpectedComplexLiteral(CompilationContext $compilationContext, $expression, $type = 'variable') + public function getExpectedComplexLiteral(CompilationContext $compilationContext, string $type = 'variable'): ?Variable { $isExpecting = $this->expecting; $symbolVariable = $this->expectingVariable; if ($isExpecting) { if (\is_object($symbolVariable)) { - if ($symbolVariable->getType() == $type || 'return_value' == $symbolVariable->getName()) { + if ($symbolVariable->getType() === $type || 'return_value' === $symbolVariable->getName()) { $symbolVariable->initVariant($compilationContext); } else { if (!$this->readOnly) { diff --git a/Library/Operators/Logical/AndOperator.php b/Library/Operators/Logical/AndOperator.php index 4cd4cf1ef..dbdf30da1 100644 --- a/Library/Operators/Logical/AndOperator.php +++ b/Library/Operators/Logical/AndOperator.php @@ -9,8 +9,11 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Logical; +use Exception; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception\CompilerException; @@ -23,14 +26,20 @@ class AndOperator extends LogicalBaseOperator protected string $bitOperator = '&&'; - public function compile($expression, CompilationContext $compilationContext) + /** + * @param $expression + * @param CompilationContext $compilationContext + * @return CompiledExpression + * @throws \Zephir\Exception + */ + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { - throw new \Exception('Missing left part of the expression'); + throw new Exception('Missing left part of the expression'); } if (!isset($expression['right'])) { - throw new \Exception('Missing right part of the expression'); + throw new Exception('Missing right part of the expression'); } $leftExpr = new Expression($expression['left']); @@ -92,7 +101,6 @@ public function compile($expression, CompilationContext $compilationContext) $statement->compile($compilationContext); $compilationContext->codePrinter->output('if ('.$flagVariable->getName().') {'); - $compilationContext->codePrinter->increaseLevel(); $rightExpr = new Expression($expression['right']); @@ -149,7 +157,6 @@ public function compile($expression, CompilationContext $compilationContext) $statement->compile($compilationContext); $compilationContext->codePrinter->decreaseLevel(); - $compilationContext->codePrinter->output('}'); return new CompiledExpression('bool', $flagVariable->getName(), $expression); diff --git a/Library/Operators/Logical/LogicalBaseOperator.php b/Library/Operators/Logical/LogicalBaseOperator.php index 8a4d84e76..ca5c8ea0f 100644 --- a/Library/Operators/Logical/LogicalBaseOperator.php +++ b/Library/Operators/Logical/LogicalBaseOperator.php @@ -9,6 +9,8 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Logical; use Zephir\CompilationContext; @@ -24,7 +26,7 @@ */ class LogicalBaseOperator extends BaseOperator { - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException('Missing left part of the expression', $expression); @@ -57,13 +59,9 @@ public function compile($expression, CompilationContext $compilationContext) case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression); switch ($variableRight->getType()) { - case 'int': - return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$variableRight->getName().')', $expression); - case 'bool': - return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$variableRight->getName().')', $expression); - case 'double': + case 'int': return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$variableRight->getName().')', $expression); case 'variable': @@ -94,13 +92,9 @@ public function compile($expression, CompilationContext $compilationContext) case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression); switch ($variableRight->getType()) { - case 'int': - return new CompiledExpression('bool', '('.$left->getBooleanCode().' '.$this->operator.' '.$variableRight->getName().')', $expression); - case 'bool': - return new CompiledExpression('bool', '('.$left->getBooleanCode().' '.$this->operator.' '.$variableRight->getName().')', $expression); - case 'double': + case 'int': return new CompiledExpression('bool', '('.$left->getBooleanCode().' '.$this->operator.' '.$variableRight->getName().')', $expression); case 'variable': @@ -120,10 +114,8 @@ public function compile($expression, CompilationContext $compilationContext) break; case 'double': switch ($right->getType()) { - case 'int': - return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$right->getCode().')', $expression); - case 'double': + case 'int': return new CompiledExpression('bool', '('.$left->getCode().' '.$this->operator.' '.$right->getCode().')', $expression); case 'bool': @@ -152,13 +144,9 @@ public function compile($expression, CompilationContext $compilationContext) case 'variable': $variableRight = $compilationContext->symbolTable->getVariableForRead($right->getCode(), $compilationContext, $expression['right']); switch ($variableRight->getType()) { - case 'int': - return new CompiledExpression('bool', '('.$variableLeft->getName().' '.$this->operator.' '.$variableRight->getName().')', $expression); - case 'bool': - return new CompiledExpression('bool', '('.$variableLeft->getName().' '.$this->operator.' '.$variableRight->getName().')', $expression); - case 'double': + case 'int': return new CompiledExpression('bool', '('.$variableLeft->getName().' '.$this->operator.' '.$variableRight->getName().')', $expression); case 'variable': @@ -212,10 +200,8 @@ public function compile($expression, CompilationContext $compilationContext) case 'double': switch ($right->getType()) { - case 'int': - return new CompiledExpression('bool', $variableLeft->getName().' '.$this->operator.' '.$right->getCode(), $expression); - case 'double': + case 'int': return new CompiledExpression('bool', $variableLeft->getName().' '.$this->operator.' '.$right->getCode(), $expression); case 'bool': @@ -251,10 +237,8 @@ public function compile($expression, CompilationContext $compilationContext) case 'string': switch ($right->getType()) { - case 'int': - return new CompiledExpression('bool', '('.$variableLeft->getName().' && Z_STRLEN_P('.$variableLeft->getName().')) '.$this->operator.' '.$right->getCode(), $expression); - case 'double': + case 'int': return new CompiledExpression('bool', '('.$variableLeft->getName().' && Z_STRLEN_P('.$variableLeft->getName().')) '.$this->operator.' '.$right->getCode(), $expression); case 'bool': @@ -296,17 +280,8 @@ public function compile($expression, CompilationContext $compilationContext) switch ($right->getType()) { /* a && 1 */ case 'int': - case 'double': - $compilationContext->headersManager->add('kernel/operators'); - $op = $this->operator; - $op1 = $variableLeftCode; - $op2 = $right->getCode(); - $compilationContext->headersManager->add('kernel/operators'); - - return new CompiledExpression('bool', 'zephir_is_true('.$op1.') '.$op.' '.$op2, $expression); - - /* a && 1 */ case 'bool': + case 'double': $compilationContext->headersManager->add('kernel/operators'); $op = $this->operator; $op1 = $variableLeftCode; @@ -321,13 +296,9 @@ public function compile($expression, CompilationContext $compilationContext) $variableRightCode = $compilationContext->backend->getVariableCode($variableRight); switch ($variableRight->getType()) { /* a(var) && a(int) */ - case 'int': - $compilationContext->headersManager->add('kernel/operators'); - - return new CompiledExpression('bool', 'zephir_is_true('.$variableLeftCode.') '.$this->operator.' '.$variableRightCode, $expression); - /* a(var) && a(bool) */ case 'bool': + case 'int': $compilationContext->headersManager->add('kernel/operators'); return new CompiledExpression('bool', 'zephir_is_true('.$variableLeftCode.') '.$this->operator.' '.$variableRightCode, $expression); diff --git a/Library/Operators/Logical/OrOperator.php b/Library/Operators/Logical/OrOperator.php index 876576fa5..6e8588e8f 100644 --- a/Library/Operators/Logical/OrOperator.php +++ b/Library/Operators/Logical/OrOperator.php @@ -9,8 +9,11 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Logical; +use Exception; use Zephir\CompilationContext; use Zephir\CompiledExpression; use Zephir\Exception\CompilerException; @@ -23,14 +26,14 @@ class OrOperator extends LogicalBaseOperator protected string $bitOperator = '||'; - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { - throw new \Exception('Missing left part of the expression'); + throw new Exception('Missing left part of the expression'); } if (!isset($expression['right'])) { - throw new \Exception('Missing right part of the expression'); + throw new Exception('Missing right part of the expression'); } $leftExpr = new Expression($expression['left']); @@ -92,7 +95,6 @@ public function compile($expression, CompilationContext $compilationContext) $statement->compile($compilationContext); $compilationContext->codePrinter->output('if (!('.$flagVariable->getName().')) {'); - $compilationContext->codePrinter->increaseLevel(); $rightExpr = new Expression($expression['right']); @@ -149,7 +151,6 @@ public function compile($expression, CompilationContext $compilationContext) $statement->compile($compilationContext); $compilationContext->codePrinter->decreaseLevel(); - $compilationContext->codePrinter->output('}'); return new CompiledExpression('bool', $flagVariable->getName(), $expression); diff --git a/Library/Operators/Other/ConcatOperator.php b/Library/Operators/Other/ConcatOperator.php index f013848fa..620dc2ec8 100644 --- a/Library/Operators/Other/ConcatOperator.php +++ b/Library/Operators/Other/ConcatOperator.php @@ -56,9 +56,9 @@ public function compile(array $expression, CompilationContext $compilationContex $optimized = $this->_getOptimizedConcat($expression, $compilationContext, $isFullString); if (\is_array($optimized)) { if (!$isFullString) { - $expected = $this->getExpectedComplexLiteral($compilationContext, $expression); + $expected = $this->getExpectedComplexLiteral($compilationContext); } else { - $expected = $this->getExpectedComplexLiteral($compilationContext, $expression, 'string'); + $expected = $this->getExpectedComplexLiteral($compilationContext, 'string'); } $expected->setDynamicTypes('string'); @@ -89,7 +89,7 @@ public function compile(array $expression, CompilationContext $compilationContex $variableRight = $compilationContext->backend->getVariableCode($variableRight); } - $expected = $this->getExpectedComplexLiteral($compilationContext, $expression); + $expected = $this->getExpectedComplexLiteral($compilationContext); $expectedCode = $compilationContext->backend->getVariableCode($expected); if ('string' == $left->getType() && 'variable' == $right->getType()) { diff --git a/Library/Operators/Other/InstanceOfOperator.php b/Library/Operators/Other/InstanceOfOperator.php index 3ae5f55fb..1567dfc74 100644 --- a/Library/Operators/Other/InstanceOfOperator.php +++ b/Library/Operators/Other/InstanceOfOperator.php @@ -64,7 +64,7 @@ public function compile($expression, CompilationContext $context): CompiledExpre default: switch ($resolved->getType()) { case 'variable': - if ('this' == $resolvedVariable) { + if ('this' === $resolvedVariable) { /** * TODO: It's an optimization variant, but maybe we need to get entry in runtime? */ diff --git a/Library/Operators/Other/IssetOperator.php b/Library/Operators/Other/IssetOperator.php index a260c36ec..45dbd814d 100644 --- a/Library/Operators/Other/IssetOperator.php +++ b/Library/Operators/Other/IssetOperator.php @@ -38,7 +38,7 @@ class IssetOperator extends BaseOperator */ public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { - if ('list' == $expression['left']['type']) { + if ('list' === $expression['left']['type']) { $left = $expression['left']['left']; } else { $left = $expression['left']; diff --git a/Library/Operators/Other/NewInstanceOperator.php b/Library/Operators/Other/NewInstanceOperator.php index 7dae34d31..3081c2d52 100644 --- a/Library/Operators/Other/NewInstanceOperator.php +++ b/Library/Operators/Other/NewInstanceOperator.php @@ -110,7 +110,7 @@ public function compile(array $expression, CompilationContext $compilationContex $classDefinition = $compilationContext->compiler->getClassDefinition($className); } - /* + /** * Classes inside the same extension */ if ($classDefinition) { @@ -118,7 +118,7 @@ public function compile(array $expression, CompilationContext $compilationContex $symbolVariable->setClassTypes($className); $symbolVariable->setAssociatedClass($classDefinition); } else { - /* + /** * Classes outside the extension */ if ($dynamic) { @@ -127,7 +127,7 @@ public function compile(array $expression, CompilationContext $compilationContex throw new CompilerException('Only dynamic/string variables can be used in new operator. '.$classNameVariable->getName(), $expression); } - /* + /** * Use a safe string version of the variable to avoid segfaults */ $compilationContext->headersManager->add('kernel/object'); @@ -179,12 +179,12 @@ public function compile(array $expression, CompilationContext $compilationContex } } - /* + /** * Mark variable initialized */ $symbolVariable->setIsInitialized(true, $compilationContext); - /* + /** * Don't check the constructor for stdclass instances */ if ($isStdClass) { diff --git a/Library/Operators/Other/NewInstanceTypeOperator.php b/Library/Operators/Other/NewInstanceTypeOperator.php index 65885e98b..d949ddf0c 100644 --- a/Library/Operators/Other/NewInstanceTypeOperator.php +++ b/Library/Operators/Other/NewInstanceTypeOperator.php @@ -34,14 +34,13 @@ class NewInstanceTypeOperator extends BaseOperator /** * Executes the operator. * - * @param array $expression + * @param array $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws CompilerException */ - public function compile(array $expression, CompilationContext $compilationContext) + public function compile(array $expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['parameters'])) { throw new CompilerException("Invalid 'parameters' for new-type", $expression); diff --git a/Library/Operators/Unary/MinusOperator.php b/Library/Operators/Unary/MinusOperator.php index 5e4f09599..2d2e74d31 100644 --- a/Library/Operators/Unary/MinusOperator.php +++ b/Library/Operators/Unary/MinusOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Unary; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -25,11 +28,10 @@ class MinusOperator extends BaseOperator * @param $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException('Missing left part of the expression'); diff --git a/Library/Operators/Unary/NotOperator.php b/Library/Operators/Unary/NotOperator.php index dd756ed39..04e05a983 100644 --- a/Library/Operators/Unary/NotOperator.php +++ b/Library/Operators/Unary/NotOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Unary; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -23,11 +26,10 @@ class NotOperator extends BaseOperator * @param $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException('Missing left part of the expression', $expression); diff --git a/Library/Operators/Unary/PlusOperator.php b/Library/Operators/Unary/PlusOperator.php index 90d25a85f..472589acc 100644 --- a/Library/Operators/Unary/PlusOperator.php +++ b/Library/Operators/Unary/PlusOperator.php @@ -9,10 +9,13 @@ * the LICENSE file that was distributed with this source code. */ +declare(strict_types=1); + namespace Zephir\Operators\Unary; use Zephir\CompilationContext; use Zephir\CompiledExpression; +use Zephir\Exception; use Zephir\Exception\CompilerException; use Zephir\Expression; use Zephir\Operators\BaseOperator; @@ -25,11 +28,10 @@ class PlusOperator extends BaseOperator * @param $expression * @param CompilationContext $compilationContext * - * @throws CompilerException - * * @return CompiledExpression + * @throws Exception */ - public function compile($expression, CompilationContext $compilationContext) + public function compile($expression, CompilationContext $compilationContext): CompiledExpression { if (!isset($expression['left'])) { throw new CompilerException('Missing left part of the expression'); From 4cca4d4ba10bbd3d2070b38eeeaa2adace3fd49e Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 20:21:58 +0100 Subject: [PATCH 33/35] Update CHANGELOG.md --- CHANGELOG.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ba5de72ad..2048c95c9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,8 +5,12 @@ The format based on [Keep a Changelog](http://keepachangelog.com) and this project adheres to [Semantic Versioning](http://semver.org). ## [Unreleased] + +## [0.14.0-beta.1] - 2021-08-06 ### Fixed - Fixed nullable dynamic argument definition [#2245](https://github.com/zephir-lang/zephir/issues/2245) + +### Changed - Changed detection of external class entries [#2213](https://github.com/zephir-lang/zephir/issues/2213) ## [0.13.5] - 2021-05-09 @@ -522,7 +526,8 @@ and this project adheres to [Semantic Versioning](http://semver.org). [#1524](https://github.com/zephir-lang/zephir/issues/1524) -[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.13.5...HEAD +[Unreleased]: https://github.com/zephir-lang/zephir/compare/0.14.0-beta.1...HEAD +[0.14.0-beta.1]: https://github.com/zephir-lang/zephir/compare/0.13.5...0.14.0-beta.1 [0.13.5]: https://github.com/zephir-lang/zephir/compare/0.13.4...0.13.5 [0.13.4]: https://github.com/zephir-lang/zephir/compare/0.13.3...0.13.4 [0.13.3]: https://github.com/zephir-lang/zephir/compare/0.13.2...0.13.3 From 0e03a5f77e67ad6a86c3956c4db53b8ce194065c Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 20:26:56 +0100 Subject: [PATCH 34/35] Bump version to `0.14.0-beta.1` --- Library/Zephir.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Library/Zephir.php b/Library/Zephir.php index 34ef7d883..c028edfc6 100644 --- a/Library/Zephir.php +++ b/Library/Zephir.php @@ -16,9 +16,9 @@ */ final class Zephir { - const VERSION = '0.13.5-$Id$'; + public const VERSION = '0.14.0-beta.1-$Id$'; - const LOGO = <<<'ASCII' + public const LOGO = <<<'ASCII' _____ __ _ /__ / ___ ____ / /_ (_)____ / / / _ \/ __ \/ __ \/ / ___/ From 7315f84929e04a0f52b276edd65cfd3673327f4a Mon Sep 17 00:00:00 2001 From: Anton Vasiliev Date: Fri, 6 Aug 2021 20:27:26 +0100 Subject: [PATCH 35/35] Regenerate `ext/` directory --- ext/php_stub.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/php_stub.h b/ext/php_stub.h index c63f94780..97666a966 100644 --- a/ext/php_stub.h +++ b/ext/php_stub.h @@ -14,7 +14,7 @@ #define PHP_STUB_VERSION "1.0.0" #define PHP_STUB_EXTNAME "stub" #define PHP_STUB_AUTHOR "Phalcon Team and contributors" -#define PHP_STUB_ZEPVERSION "0.13.5-$Id$" +#define PHP_STUB_ZEPVERSION "0.14.0-beta.1-$Id$" #define PHP_STUB_DESCRIPTION "Description test for
Test Extension." typedef struct _zephir_struct_db {