cvs: ZendEngine2 / zend_constants.c
| From: | Stanislav Malyshev | Date: | Mon, 16 Jun 2003 10:16:50 +0000 |
| Subject: | cvs: ZendEngine2 / zend_constants.c | ||
| Groups: | php.zend-engine.cvs | ||
| Request: | Send a blank email to php-zend-engine-cvs+get-1380@lists.php.net to get a copy of this message | ||
stas Mon Jun 16 06:16:50 2003 EDT
Modified files:
/ZendEngine2 zend_constants.c
Log:
support for self:: and parent:: constants
Index: ZendEngine2/zend_constants.c
diff -u ZendEngine2/zend_constants.c:1.56 ZendEngine2/zend_constants.c:1.57
--- ZendEngine2/zend_constants.c:1.56 Sun Jun 15 11:34:00 2003
+++ ZendEngine2/zend_constants.c Mon Jun 16 06:16:50 2003
@@ -17,7 +17,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: zend_constants.c,v 1.56 2003/06/15 15:34:00 sebastian Exp $ */
+/* $Id: zend_constants.c,v 1.57 2003/06/16 10:16:50 stas Exp $ */
#include "zend.h"
#include "zend_constants.h"
@@ -217,22 +217,48 @@
if((colon = memchr(name, ':', name_len)) && colon[1] == ':') {
/* class constant */
- zend_class_entry **ce;
+ zend_class_entry **ce = NULL, *scope;
int class_name_len = colon-name;
int const_name_len = name_len - class_name_len - 2;
char *constant_name = colon+2;
zval **ret_constant;
-
+
+ if(EG(in_execution)) {
+ scope = EG(scope);
+ } else {
+ scope = CG(active_class_entry);
+ }
+
lookup_name = do_alloca(class_name_len+1);
zend_str_tolower_copy(lookup_name, name, class_name_len);
lookup_name[class_name_len] = '\0';
- if(zend_lookup_class(lookup_name, class_name_len, &ce TSRMLS_CC) != SUCCESS) {
- retval = 0;
+ if(class_name_len == sizeof("self")-1 && strcmp(lookup_name, "self")
== 0) {
+ if(scope) {
+ ce = &scope;
+ } else {
+ zend_error(E_ERROR, "Cannot access self:: when no class scope is active");
+ retval = 0;
+ }
+ } else if (class_name_len == sizeof("parent")-1 && strcmp(lookup_name,
"parent") == 0) {
+ if (!scope) {
+ zend_error(E_ERROR, "Cannot access parent:: when no class scope is active");
+ } else if (!scope->parent) {
+ zend_error(E_ERROR, "Cannot access parent:: when current class scope has no parent");
+ } else {
+ ce = &scope->parent;
+ }
} else {
- if (zend_hash_find(&((*ce)->constants_table), constant_name, const_name_len+1, (void **)
&ret_constant) != SUCCESS) {
+ if(zend_lookup_class(lookup_name, class_name_len, &ce TSRMLS_CC) != SUCCESS) {
retval = 0;
}
+ }
+ if(retval && ce) {
+ if (zend_hash_find(&((*ce)->constants_table), constant_name, const_name_len+1, (void **)
&ret_constant) != SUCCESS) {
+ retval = 0;
+ }
+ } else {
+ retval = 0;
}
if(retval) {