Skip to content

Commit 889d536

Browse files
committed
Backport zend_get_object_type_case functions from PHP 8.2
See: php/php-src@733023b
1 parent e3d1d37 commit 889d536

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

src/phongo_compat.c

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616

1717
#include <php.h>
1818

19+
#include "phongo_compat.h"
20+
1921
#ifdef ZEND_HASH_GET_APPLY_COUNT /* PHP 7.2 or earlier recursion protection */
2022
zend_bool php_phongo_zend_hash_apply_protection_begin(HashTable* ht)
2123
{
@@ -44,7 +46,7 @@ zend_bool php_phongo_zend_hash_apply_protection_end(HashTable* ht)
4446
}
4547
return 1;
4648
}
47-
#else /* PHP 7.3 or later */
49+
#else /* PHP 7.3 or later */
4850
zend_bool php_phongo_zend_hash_apply_protection_begin(zend_array* ht)
4951
{
5052
if (GC_IS_RECURSIVE(ht)) {
@@ -66,4 +68,22 @@ zend_bool php_phongo_zend_hash_apply_protection_end(zend_array* ht)
6668
}
6769
return 1;
6870
}
69-
#endif
71+
#endif /* ZEND_HASH_GET_APPLY_COUNT */
72+
73+
#if PHP_VERSION_ID < 80200
74+
const char* zend_get_object_type_case(const zend_class_entry* ce, zend_bool upper_case)
75+
{
76+
if (ce->ce_flags & ZEND_ACC_TRAIT) {
77+
return upper_case ? "Trait" : "trait";
78+
}
79+
if (ce->ce_flags & ZEND_ACC_INTERFACE) {
80+
return upper_case ? "Interface" : "interface";
81+
}
82+
#if PHP_VERSION_ID >= 80100
83+
if (ce->ce_flags & ZEND_ACC_ENUM) {
84+
return upper_case ? "Enum" : "enum";
85+
}
86+
#endif /* PHP_VERSION_ID > 80100 */
87+
return upper_case ? "Class" : "class";
88+
}
89+
#endif /* PHP_VERSION_ID < 80200 */

src/phongo_compat.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,4 +315,11 @@ static inline zend_bool zend_ini_parse_bool(zend_string* str)
315315
zend_bool php_phongo_zend_hash_apply_protection_begin(HashTable* ht);
316316
zend_bool php_phongo_zend_hash_apply_protection_end(HashTable* ht);
317317

318+
/* zend_get_object_type_case functions were introduced in PHP 8.2 */
319+
#if PHP_VERSION_ID < 80200
320+
const char* zend_get_object_type_case(const zend_class_entry* ce, zend_bool upper_case);
321+
#define zend_get_object_type(ce) zend_get_object_type_case((ce), false)
322+
#define zend_get_object_type_uc(ce) zend_get_object_type_case((ce), true)
323+
#endif /* PHP_VERSION_ID < 80200 */
324+
318325
#endif /* PHONGO_COMPAT_H */

0 commit comments

Comments
 (0)