com php-src: Fix procedural finfo calls in methods: Zend/zend_API.h ext/fileinfo/fileinfo.c ext/fileinfo/ tests/precedural_finfo_in_method.phpt
| From: | Nikita Popov | Date: | Thu, 16 Oct 2014 12:24:23 +0000 |
| Subject: | com php-src: Fix procedural finfo calls in methods: Zend/zend_API.h ext/fileinfo/fileinfo.c ext/fileinfo/ tests/precedural_finfo_in_method.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-82376@lists.php.net to get a copy of this message | ||
Commit: cf5920e8aa8958d47f391c483d7399fc77a58092
Author: Nikita Popov <nikic@php.net> Thu, 16 Oct 2014 14:24:23 +0200
Parents: 53a8584123f359c2c32f1869d98e4dd9e0a7a6ab
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=cf5920e8aa8958d47f391c483d7399fc77a58092
Log:
Fix procedural finfo calls in methods
getThis() will return the $this of the calling method.
Changed paths:
M Zend/zend_API.h
M ext/fileinfo/fileinfo.c
A ext/fileinfo/tests/precedural_finfo_in_method.phpt
Diff:
diff --git a/Zend/zend_API.h b/Zend/zend_API.h
index b23b5b3..b2faf7e 100644
--- a/Zend/zend_API.h
+++ b/Zend/zend_API.h
@@ -342,6 +342,7 @@ ZEND_API zval *zend_read_static_property(zend_class_entry *scope, const char *na
ZEND_API char *zend_get_type_by_const(int type);
#define getThis() (Z_OBJ(EX(This)) ? &EX(This) : NULL)
+#define ZEND_IS_METHOD_CALL() (EX(func)->common.scope != NULL)
#define WRONG_PARAM_COUNT ZEND_WRONG_PARAM_COUNT()
#define WRONG_PARAM_COUNT_WITH_RETVAL(ret) ZEND_WRONG_PARAM_COUNT_WITH_RETVAL(ret)
diff --git a/ext/fileinfo/fileinfo.c b/ext/fileinfo/fileinfo.c
index f365b38..6879926 100644
--- a/ext/fileinfo/fileinfo.c
+++ b/ext/fileinfo/fileinfo.c
@@ -57,7 +57,7 @@ typedef struct _finfo_object {
} finfo_object;
#define FILEINFO_DECLARE_INIT_OBJECT(object) \
- zval *object = getThis();
+ zval *object = ZEND_IS_METHOD_CALL() ? getThis() : NULL;
static inline finfo_object *php_finfo_fetch_object(zend_object *obj) {
return (finfo_object *)((char*)(obj) - XtOffsetOf(finfo_object, zo));
diff --git a/ext/fileinfo/tests/precedural_finfo_in_method.phpt
b/ext/fileinfo/tests/precedural_finfo_in_method.phpt
new file mode 100644
index 0000000..8c30b8a
--- /dev/null
+++ b/ext/fileinfo/tests/precedural_finfo_in_method.phpt
@@ -0,0 +1,18 @@
+--TEST--
+Using procedural finfo API in a method
+--FILE--
+<?php
+
+class Test {
+ public function method() {
+ $finfo = finfo_open(FILEINFO_MIME);
+ var_dump(finfo_file($finfo, __FILE__));
+ }
+}
+
+$test = new Test;
+$test->method();
+
+?>
+--EXPECT--
+string(28) "text/plain; charset=us-ascii"