Skip to content

Commit

Permalink
Fix procedural finfo calls in methods
Browse files Browse the repository at this point in the history
getThis() will return the $this of the calling method.
  • Loading branch information
nikic committed Oct 16, 2014
1 parent 53a8584 commit cf5920e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions Zend/zend_API.h
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion ext/fileinfo/fileinfo.c
Expand Up @@ -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));
Expand Down
18 changes: 18 additions & 0 deletions 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"

0 comments on commit cf5920e

Please sign in to comment.