Fix procedural finfo calls in methods
authorNikita Popov <nikic@php.net>
Thu, 16 Oct 2014 12:24:23 +0000 (14:24 +0200)
committerNikita Popov <nikic@php.net>
Thu, 16 Oct 2014 12:24:23 +0000 (14:24 +0200)
getThis() will return the $this of the calling method.

Zend/zend_API.h
ext/fileinfo/fileinfo.c
ext/fileinfo/tests/precedural_finfo_in_method.phpt [new file with mode: 0644]

index b23b5b32f05d5da876f192bcf9fe54ac839c859d..b2faf7e2535d5dec6674f040d588faab468f5d15 100644 (file)
@@ -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)
index f365b38573d7ee358f725c4f4927006250d417d6..6879926ecaa40b3a431e4e356297d2c77d5a0af4 100644 (file)
@@ -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 (file)
index 0000000..8c30b8a
--- /dev/null
@@ -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"