diff options
author | Andi Gutmans <andi@php.net> | 2001-11-30 16:29:47 +0000 |
---|---|---|
committer | Andi Gutmans <andi@php.net> | 2001-11-30 16:29:47 +0000 |
commit | e858d27888471107a4816d62033db785fab5f2da (patch) | |
tree | 72af463fe00499ac25ec0d6140cb7efff4ae32c0 /Zend/zend_execute_API.c | |
parent | 7f66d5e99aa51dd90df5f62b452653aaae53c21c (diff) | |
download | php-git-e858d27888471107a4816d62033db785fab5f2da.tar.gz |
- Initial support for class constants. There are still a few semantic
- issues which need to be looked into but basically it seems to work.
- Example:
<?php
class foo
{
const hey = "hello";
}
print foo::hey;
?>
Diffstat (limited to 'Zend/zend_execute_API.c')
-rw-r--r-- | Zend/zend_execute_API.c | 50 |
1 files changed, 42 insertions, 8 deletions
diff --git a/Zend/zend_execute_API.c b/Zend/zend_execute_API.c index 5cff595e15..a6790aa357 100644 --- a/Zend/zend_execute_API.c +++ b/Zend/zend_execute_API.c @@ -289,6 +289,7 @@ ZEND_API int zend_is_true(zval *op) return i_zend_is_true(op); } +#include "../TSRM/tsrm_strtok_r.h" ZEND_API int zval_update_constant(zval **pp, void *arg TSRMLS_DC) { @@ -304,19 +305,52 @@ ZEND_API int zval_update_constant(zval **pp, void *arg TSRMLS_DC) refcount = p->refcount; - if (!zend_get_constant(p->value.str.val, p->value.str.len, &const_value TSRMLS_CC)) { - zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", - p->value.str.val, - p->value.str.val); - p->type = IS_STRING; - if (!inline_change) { - zval_copy_ctor(p); + if (strchr(p->value.str.val, ':')) { + char *cur, *temp; + char *last; + zend_class_entry *ce; + zval **value; + + last = tsrm_strtok_r(p->value.str.val, ":", &temp); + + if (zend_hash_find(EG(class_table), last, strlen(last)+1, &ce) == FAILURE) { + zend_error(E_ERROR, "Invalid class! Improve this error message"); } - } else { + + for(;;) { + cur = tsrm_strtok_r(NULL, ":", &temp); + if (!cur) { + break; + } + if (zend_hash_find(EG(class_table), last, strlen(last)+1, &ce) == FAILURE) { + zend_error(E_ERROR, "Invalid class! Improve this error message"); + } + last = cur; + } + if (zend_hash_find(&ce->constants, last, strlen(last)+1, (void **) &value) == FAILURE) { + zend_error(E_ERROR, "Invalid class! Improve this error message"); + } + const_value = **value; + zval_copy_ctor(&const_value); if (inline_change) { STR_FREE(p->value.str.val); } *p = const_value; + } else { + if (!zend_get_constant(p->value.str.val, p->value.str.len, &const_value TSRMLS_CC)) { + zend_error(E_NOTICE, "Use of undefined constant %s - assumed '%s'", + p->value.str.val, + p->value.str.val); + p->type = IS_STRING; + if (!inline_change) { + zval_copy_ctor(p); + } + } else { + if (inline_change) { + STR_FREE(p->value.str.val); + } + *p = const_value; + } } INIT_PZVAL(p); p->refcount = refcount; |