]> granicus.if.org Git - php/commitdiff
Test a few more error conditions in the compiler
authorNikita Popov <nikic@php.net>
Mon, 22 Sep 2014 22:57:00 +0000 (00:57 +0200)
committerNikita Popov <nikic@php.net>
Mon, 22 Sep 2014 22:57:00 +0000 (00:57 +0200)
Zend/tests/class_name_as_scalar_error_007.phpt [new file with mode: 0644]
Zend/tests/duplicate_label_error.phpt [new file with mode: 0644]
Zend/tests/magic_const_in_global_scope.phpt [new file with mode: 0644]
Zend/tests/special_name_error1.phpt [new file with mode: 0644]
Zend/tests/special_name_error2.phpt [new file with mode: 0644]
Zend/tests/special_name_error3.phpt [new file with mode: 0644]
Zend/zend_compile.c

diff --git a/Zend/tests/class_name_as_scalar_error_007.phpt b/Zend/tests/class_name_as_scalar_error_007.phpt
new file mode 100644 (file)
index 0000000..2bfa5f3
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Cannot access self::class when no class scope is active
+--FILE--
+<?php
+
+var_dump(self::class);
+
+?>
+--EXPECTF--
+Fatal error: Cannot access self::class when no class scope is active in %s on line %d
diff --git a/Zend/tests/duplicate_label_error.phpt b/Zend/tests/duplicate_label_error.phpt
new file mode 100644 (file)
index 0000000..c89d7a6
--- /dev/null
@@ -0,0 +1,12 @@
+--TEST--
+Duplicate labels are not allowed
+--FILE--
+<?php
+
+foo:
+foo:
+goto foo;
+
+?>
+--EXPECTF--
+Fatal error: Label 'foo' already defined in %s on line %d
diff --git a/Zend/tests/magic_const_in_global_scope.phpt b/Zend/tests/magic_const_in_global_scope.phpt
new file mode 100644 (file)
index 0000000..31f7eae
--- /dev/null
@@ -0,0 +1,26 @@
+--TEST--
+Test use of magic constants in the global scope
+--FILE--
+<?php
+
+var_dump(
+    __LINE__,
+    __FILE__,
+    __DIR__,
+    __FUNCTION__,
+    __METHOD__,
+    __CLASS__,
+    __TRAIT__,
+    __NAMESPACE__
+);
+
+?>
+--EXPECTF--
+int(4)
+string(%d) "%s"
+string(%d) "%s"
+string(0) ""
+string(0) ""
+string(0) ""
+string(0) ""
+string(0) ""
diff --git a/Zend/tests/special_name_error1.phpt b/Zend/tests/special_name_error1.phpt
new file mode 100644 (file)
index 0000000..63bf5a6
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Cannot use special class name as namespace
+--FILE--
+<?php
+
+namespace self;
+
+?>
+--EXPECTF--
+Fatal error: Cannot use 'self' as namespace name in %s on line %d
diff --git a/Zend/tests/special_name_error2.phpt b/Zend/tests/special_name_error2.phpt
new file mode 100644 (file)
index 0000000..08122b3
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Cannot use special class name as alias
+--FILE--
+<?php
+
+use Foo\Bar as self;
+
+?>
+--EXPECTF--
+Fatal error: Cannot use Foo\Bar as self because 'self' is a special class name in %s on line %d
diff --git a/Zend/tests/special_name_error3.phpt b/Zend/tests/special_name_error3.phpt
new file mode 100644 (file)
index 0000000..74e69f1
--- /dev/null
@@ -0,0 +1,10 @@
+--TEST--
+Cannot use special class name as trait name
+--FILE--
+<?php
+
+trait self {}
+
+?>
+--EXPECTF--
+Fatal error: Cannot use 'self' as class name as it is reserved in %s on line %d
index ca4aa695ad866f3fce4e13681a22c585f423ca32..262dc8c1885a55f8ee25384595d302e1e4aa2aba 100644 (file)
@@ -3256,11 +3256,9 @@ void zend_compile_goto(zend_ast *ast TSRMLS_DC) /* {{{ */
 
 void zend_compile_label(zend_ast *ast TSRMLS_DC) /* {{{ */
 {
-       zval *label = zend_ast_get_zval(ast->child[0]);
+       zend_string *label = zend_ast_get_str(ast->child[0]);
        zend_label dest;
 
-       ZEND_ASSERT(Z_TYPE_P(label) == IS_STRING);
-
        if (!CG(context).labels) {
                ALLOC_HASHTABLE(CG(context).labels);
                zend_hash_init(CG(context).labels, 8, NULL, ptr_dtor, 0);
@@ -3269,8 +3267,8 @@ void zend_compile_label(zend_ast *ast TSRMLS_DC) /* {{{ */
        dest.brk_cont = CG(context).current_brk_cont;
        dest.opline_num = get_next_op_number(CG(active_op_array));
 
-       if (!zend_hash_add_mem(CG(context).labels, Z_STR_P(label), &dest, sizeof(zend_label))) {
-               zend_error_noreturn(E_COMPILE_ERROR, "Label '%s' already defined", Z_STRVAL_P(label));
+       if (!zend_hash_add_mem(CG(context).labels, label, &dest, sizeof(zend_label))) {
+               zend_error_noreturn(E_COMPILE_ERROR, "Label '%s' already defined", label->val);
        }
 }
 /* }}} */