com php-src: Use FETCH_CLASS_EXCEPTION for instanceof : Zend/tests/self_instanceof_outside_class.phpt Z end/zend_compile.c Zend/zend_vm_def.h
Zend/zend _vm_execute.h
| From: | Nikita Popov | Date: | Mon, 14 Dec 2015 16:50:20 +0000 |
| Subject: | com php-src: Use FETCH_CLASS_EXCEPTION for instanceof : Zend/tests/self_instanceof_outside_class.phpt Z end/zend_compile.c Zend/zend_vm_def.h Zend/zend _vm_execute.h |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-90273@lists.php.net to get a copy of this message | ||
Commit: 56f1106162cdca2cdebfd9321545cc448da32d21
Author: Nikita Popov <nikic@php.net> Mon, 14 Dec 2015 17:50:20 +0100
Parents: 7078627d22c1d32a17b193eb6bfe83242d877371
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=56f1106162cdca2cdebfd9321545cc448da32d21
Log:
Use FETCH_CLASS_EXCEPTION for instanceof
This does not collide with NO_AUTOLOAD -- missing classes will be
silenced, but invalid use of self etc will result in an exception
instead of a fatal error.
Changed paths:
A Zend/tests/self_instanceof_outside_class.phpt
M Zend/zend_compile.c
M Zend/zend_vm_def.h
M Zend/zend_vm_execute.h
Diff:
diff --git a/Zend/tests/self_instanceof_outside_class.phpt
b/Zend/tests/self_instanceof_outside_class.phpt
new file mode 100644
index 0000000..4caef37
--- /dev/null
+++ b/Zend/tests/self_instanceof_outside_class.phpt
@@ -0,0 +1,17 @@
+--TEST--
+instanceof self outside a class
+--FILE--
+<?php
+
+$fn = function() {
+ try {
+ new stdClass instanceof self;
+ } catch (Error $e) {
+ echo $e->getMessage(), "\n";
+ }
+};
+$fn();
+
+?>
+--EXPECT--
+Cannot access self:: when no class scope is active
diff --git a/Zend/zend_compile.c b/Zend/zend_compile.c
index ce9477f..e875278 100644
--- a/Zend/zend_compile.c
+++ b/Zend/zend_compile.c
@@ -6545,7 +6545,8 @@ void zend_compile_instanceof(znode *result, zend_ast *ast) /* {{{ */
"instanceof expects an object instance, constant given");
}
- zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_NO_AUTOLOAD);
+ zend_compile_class_ref_ex(&class_node, class_ast,
+ ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_EXCEPTION);
opline = zend_emit_op_tmp(result, ZEND_INSTANCEOF, &obj_node, NULL);
diff --git a/Zend/zend_vm_def.h b/Zend/zend_vm_def..h
index ce85541..eccb65a 100644
--- a/Zend/zend_vm_def.h
+++ b/Zend/zend_vm_def.h
@@ -7173,6 +7173,7 @@ ZEND_VM_C_LABEL(try_instanceof):
ce = zend_fetch_class(NULL, opline->op2.num);
if (UNEXPECTED(ce == NULL)) {
ZEND_ASSERT(EG(exception));
+ FREE_OP1();
HANDLE_EXCEPTION();
}
} else {
diff --git a/Zend/zend_vm_execute.h b/Zend/zend_vm_execute.h
index 8c15ff9..71438dd 100644
--- a/Zend/zend_vm_execute.h
+++ b/Zend/zend_vm_execute.h
@@ -33206,6 +33206,7 @@ try_instanceof:
ce = zend_fetch_class(NULL, opline->op2.num);
if (UNEXPECTED(ce == NULL)) {
ZEND_ASSERT(EG(exception));
+
HANDLE_EXCEPTION();
}
} else {
@@ -34096,6 +34097,7 @@ try_instanceof:
ce = zend_fetch_class(NULL, opline->op2.num);
if (UNEXPECTED(ce == NULL)) {
ZEND_ASSERT(EG(exception));
+
HANDLE_EXCEPTION();
}
} else {
@@ -35496,6 +35498,7 @@ try_instanceof:
ce = zend_fetch_class(NULL, opline->op2.num);
if (UNEXPECTED(ce == NULL)) {
ZEND_ASSERT(EG(exception));
+
HANDLE_EXCEPTION();
}
} else {
@@ -42855,6 +42858,7 @@ try_instanceof:
ce = zend_fetch_class(NULL, opline->op2.num);
if (UNEXPECTED(ce == NULL)) {
ZEND_ASSERT(EG(exception));
+ zval_ptr_dtor_nogc(free_op1);
HANDLE_EXCEPTION();
}
} else {
@@ -43188,6 +43192,7 @@ try_instanceof:
ce = zend_fetch_class(NULL, opline->op2.num);
if (UNEXPECTED(ce == NULL)) {
ZEND_ASSERT(EG(exception));
+ zval_ptr_dtor_nogc(free_op1);
HANDLE_EXCEPTION();
}
} else {
@@ -43764,6 +43769,7 @@ try_instanceof:
ce = zend_fetch_class(NULL, opline->op2.num);
if (UNEXPECTED(ce == NULL)) {
ZEND_ASSERT(EG(exception));
+ zval_ptr_dtor_nogc(free_op1);
HANDLE_EXCEPTION();
}
} else {