diff options
Diffstat (limited to 'zend/exists.cpp')
-rw-r--r-- | zend/exists.cpp | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/zend/exists.cpp b/zend/exists.cpp index 1177e47..21d3184 100644 --- a/zend/exists.cpp +++ b/zend/exists.cpp @@ -1,7 +1,7 @@ /** * Exists.cpp * - * This file holds the implementation of all *_exists() functions, + * This file holds the implementation of all *_exists() functions, * like class_exists(), et cetera * * @author andot <https://github.com/andot> @@ -33,41 +33,42 @@ namespace Php { * @param autoload * @return bool */ -bool class_exists(const char *classname, size_t len, bool autoload) +bool class_exists(const char *classname, size_t len, bool autoload) { // we need the tsrm_ls variable TSRMLS_FETCH(); - // we're going to load a class-entry - zend_class_entry **ce; - // should we autoload the class? - if (autoload) + if (autoload) { + // retrieve class entry + auto *ce = zend_lookup_class(zend_string_init(classname, len, 1) TSRMLS_CC); + // no auto-load - if (SUCCESS != zend_lookup_class(classname, len, &ce TSRMLS_CC)) return false; + if (!ce) return false; // the found "class" could also be an interface or trait, which we do no want - return ((*ce)->ce_flags & (ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT - ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) == 0; + return (ce->ce_flags & (ZEND_ACC_INTERFACE | (ZEND_ACC_TRAIT - ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))) == 0; } else { // starting slashes can be ignored if (len > 0 && classname[0] == '\\') { classname++; len--; } - - // all classes are in lowercase in the hash, so we make - // a temporary buffer for storing the lowercase class name - // (is this smart? memory allocation is expensive!) - std::unique_ptr<char[]> lc_name(new char[len + 1]); - + + // allocate a zend_string + auto *string = zend_string_alloc(len, 1); + // copy the name to lowercase, but ignore the starting slash (if there is one) - zend_str_tolower_copy(lc_name.get(), classname, len); + zend_str_tolower_copy(ZSTR_VAL(string), classname, len); // see if there is a class with this name - if (SUCCESS != zend_hash_find(EG(class_table), lc_name.get(), len + 1, (void **) &ce)) return false; - - // the found "class" could also be an interface or trait, which we do no want - return !(((*ce)->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); + auto *val = zend_hash_find(EG(class_table), string); + + // check whether something was found + if (val == nullptr) return false; + + // the "something" could also be an interface or trait, which we do no want + return !(((Z_CE_P(val))->ce_flags & (ZEND_ACC_INTERFACE | ZEND_ACC_TRAIT)) > ZEND_ACC_EXPLICIT_ABSTRACT_CLASS); } } |