]> granicus.if.org Git - php/commitdiff
Add ability to reference self:: and parent:: in constant initializers
authorZeev Suraski <zeev@php.net>
Mon, 10 Feb 2003 09:45:27 +0000 (09:45 +0000)
committerZeev Suraski <zeev@php.net>
Mon, 10 Feb 2003 09:45:27 +0000 (09:45 +0000)
(bug #21849)

Zend/zend_execute.c
Zend/zend_execute_API.c

index 3693fc639782f1e67a179c9d193dd1da7bc826fa..8e4ba13a361f4296f8df865fcd36e40556241902 100644 (file)
@@ -2211,7 +2211,7 @@ int zend_fetch_class_handler(ZEND_OPCODE_HANDLER_ARGS)
        if (EX(opline)->op1.op_type == IS_UNUSED) {
                if (EX(opline)->extended_value == ZEND_FETCH_CLASS_SELF) {
                        if (!EG(scope)) {
-                               zend_error(E_ERROR, "Cannot fetch self:: when no class scope is active");
+                               zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
                        }
                        EX_T(EX(opline)->result.u.var).EA.class_entry = EG(scope);
                        NEXT_OPCODE();
@@ -2220,10 +2220,10 @@ int zend_fetch_class_handler(ZEND_OPCODE_HANDLER_ARGS)
                        NEXT_OPCODE();
                } else if (EX(opline)->extended_value == ZEND_FETCH_CLASS_PARENT) {
                        if (!EG(scope)) {
-                               zend_error(E_ERROR, "Cannot fetch parent:: when no class scope is active");
+                               zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
                        }
                        if (!EG(scope)->parent) {
-                               zend_error(E_ERROR, "Cannot fetch parent:: as current class scope has no parent");
+                               zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
                        }
                        EX_T(EX(opline)->result.u.var).EA.class_entry = EG(scope)->parent;
                        NEXT_OPCODE();
index 3788ae263fcfa1b91fe6cbc3acac7fb3bd9a068c..b170603bec27a0333f5ccdae48817da40f66c8e3 100644 (file)
@@ -378,6 +378,23 @@ ZEND_API int zval_update_constant(zval **pp, void *arg TSRMLS_DC)
 
                        last = tsrm_strtok_r(p->value.str.val, ":", &temp);
 
+                       if (strcasecmp(last, "self")==0) {
+                               if (EG(scope)) {
+                                       last = EG(scope)->name;
+                               } else {
+                                       zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
+                               }
+                       } else if (strcasecmp(last, "parent")==0) {
+                               if (!EG(scope)) {
+                                       zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
+                               } else if (!EG(scope)->parent) {
+                                       zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
+                               } else {
+                                       last = EG(scope)->parent->name;
+                               }
+                       }
+
+
                        if (zend_lookup_class(last, strlen(last), &ce TSRMLS_CC) == FAILURE) {
                                zend_error(E_ERROR, "Undefined class '%s'", last);
                        }