summaryrefslogtreecommitdiff
path: root/Lib/php
diff options
context:
space:
mode:
authorOlly Betts <olly@survex.com>2022-01-21 14:32:36 +1300
committerOlly Betts <olly@survex.com>2022-01-21 14:32:36 +1300
commit4f5dfd596d6471b61f6d45a12c6536ab1173856f (patch)
treef11555eaf2587668cadea89be27b7d99c22cada4 /Lib/php
parent91470ca62defe9a91df627008ae90686479c1063 (diff)
downloadswig-4f5dfd596d6471b61f6d45a12c6536ab1173856f.tar.gz
[php] Provide zend_class_implements_interface() for 7.x
It seems instanceof_function_ex() isn't a viable option for PHP 7.3 and earlier - the implementation is strangely wrong. So let's just provide a compatibility implementation which does what zend_class_implements_interface() does in 8.x and use that for all 7.x so there are fewer variants to worry about testing.
Diffstat (limited to 'Lib/php')
-rw-r--r--Lib/php/phprun.swg24
1 files changed, 18 insertions, 6 deletions
diff --git a/Lib/php/phprun.swg b/Lib/php/phprun.swg
index 622200836..d2ac5df8c 100644
--- a/Lib/php/phprun.swg
+++ b/Lib/php/phprun.swg
@@ -96,12 +96,24 @@ static int default_error_code = E_ERROR;
static zend_class_entry SWIG_Php_swig_wrapped_interface_ce;
#if PHP_MAJOR_VERSION == 7
-/* The sense of parameter 3 of instanceof_function_ex() changed in PHP 7.4! */
-# if PHP_MINOR_VERSION <= 3
-# define zend_class_implements_interface(C, I) instanceof_function_ex(C, I, 0)
-# else
-# define zend_class_implements_interface(C, I) instanceof_function_ex(C, I, 1)
-# endif
+/* zend_class_implements_interface() was new in PHP 8.0.
+ *
+ * We could use instanceof_function_ex(C, I, 1) here for 7.4, but for 7.3
+ * and earlier that doesn't work, so instead we just provide a compatibility
+ * implementation which does what zend_class_implements_interface() does in 8.x
+ * and use that for all 7.x so there are fewer variants to worry about testing.
+ */
+static int zend_class_implements_interface(const zend_class_entry *class_ce, const zend_class_entry *interface_ce) {
+ uint32_t i;
+ if (class_ce->num_interfaces) {
+ for (i = 0; i < class_ce->num_interfaces; i++) {
+ if (class_ce->interfaces[i] == interface_ce) {
+ return 1;
+ }
+ }
+ }
+ return 0;
+}
#endif
/* used to wrap returned objects in so we know whether they are newobject