Permalink
Browse files

Fixed bug #42820 (defined() on constant with namespace prefixes tries…

… to load class).
  • Loading branch information...
1 parent 6805501 commit eb0c56ada1e2d6f4155c32c23cea56502de7751e Dmitry Stogov committed Oct 3, 2007
Showing with 48 additions and 8 deletions.
  1. +2 −0 NEWS
  2. +31 −0 Zend/tests/bug42820.phpt
  3. +1 −1 Zend/zend_builtin_functions.c
  4. +2 −0 Zend/zend_compile.h
  5. +4 −2 Zend/zend_constants.c
  6. +8 −5 Zend/zend_execute_API.c
View
@@ -35,6 +35,8 @@ PHP NEWS
- Improved and cleaned CGI code. FastCGI is now always enabled and can not be
disabled. See sapi/cgi/CHANGES for more details. (Dmitry)
+- Fixed bug #42820 (defined() on constant with namespace prefixes tries to load
+ class). (Dmitry)
- Fixed bug #42798 (__autoload() not triggered for classes used in method
signature). (Dmitry)
- Fixed bug #42657 (ini_get() returns incorrect value when default is NULL).
@@ -0,0 +1,31 @@
+--TEST--
+Bug #42820 (defined() on constant with namespace prefixes tries to load class)
+--FILE--
+<?php
+namespace ns;
+const ok = 0;
+class foo {
+ const ok = 0;
+}
+var_dump(defined('ns::ok'));
+var_dump(defined('ns::bug'));
+var_dump(defined('::ns::ok'));
+var_dump(defined('::ns::bug'));
+var_dump(defined('ns::foo::ok'));
+var_dump(defined('ns::foo::bug'));
+var_dump(defined('::ns::foo::ok'));
+var_dump(defined('::ns::foo::bug'));
+var_dump(defined('ns::bar::bug'));
+var_dump(defined('::ns::bar::bug'));
+--EXPECT--
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(true)
+bool(false)
+bool(false)
+bool(false)
+
@@ -545,7 +545,7 @@ ZEND_FUNCTION(defined)
}
convert_to_string_ex(var);
- if (zend_get_constant_ex(Z_STRVAL_PP(var), Z_STRLEN_PP(var), &c, NULL, 0 TSRMLS_CC)) {
+ if (zend_get_constant_ex(Z_STRVAL_PP(var), Z_STRLEN_PP(var), &c, NULL, ZEND_FETCH_CLASS_SILENT TSRMLS_CC)) {
zval_dtor(&c);
RETURN_TRUE;
} else {
View
@@ -597,9 +597,11 @@ int zendlex(znode *zendlval TSRMLS_DC);
#define ZEND_FETCH_CLASS_AUTO 5
#define ZEND_FETCH_CLASS_INTERFACE 6
#define ZEND_FETCH_CLASS_STATIC 7
+#define ZEND_FETCH_CLASS_MASK 0x0f
#define ZEND_FETCH_CLASS_RT_NS_CHECK 0x20
#define ZEND_FETCH_CLASS_RT_NS_NAME 0x40
#define ZEND_FETCH_CLASS_NO_AUTOLOAD 0x80
+#define ZEND_FETCH_CLASS_SILENT 0x0100
/* variable parsing type (compile-time) */
#define ZEND_PARSED_MEMBER (1<<0)
@@ -274,7 +274,7 @@ ZEND_API int zend_get_constant_ex(char *name, uint name_len, zval *result, zend_
if (name[0] == ':' && name[1] == ':') {
name += 2;
name_len -= 2;
- flags = 0;
+ flags &= ZEND_FETCH_CLASS_SILENT;
}
@@ -374,7 +374,9 @@ ZEND_API int zend_get_constant_ex(char *name, uint name_len, zval *result, zend_
retval = 1;
return zend_get_constant(name, name_len, result TSRMLS_CC);
}
- zend_error(E_ERROR, "Class '%s' not found", class_name);
+ if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
+ zend_error(E_ERROR, "Class '%s' not found", class_name);
+ }
}
retval = 0;
}
@@ -1513,8 +1513,9 @@ zend_class_entry *zend_fetch_class(const char *class_name, uint class_name_len,
zend_class_entry **pce;
int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
int rt_ns_check = (fetch_type & ZEND_FETCH_CLASS_RT_NS_CHECK) ? 1 : 0;
+ int silent = (fetch_type & ZEND_FETCH_CLASS_SILENT) != 0;
- fetch_type = fetch_type & ~ZEND_FETCH_CLASS_NO_AUTOLOAD;
+ fetch_type &= ZEND_FETCH_CLASS_MASK;
check_fetch_type:
switch (fetch_type) {
case ZEND_FETCH_CLASS_SELF:
@@ -1568,10 +1569,12 @@ zend_class_entry *zend_fetch_class(const char *class_name, uint class_name_len,
zend_lookup_class_ex(class_name, class_name_len, 1, &pce TSRMLS_CC)==SUCCESS) {
return *pce;
}
- if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
- zend_error(E_ERROR, "Interface '%s' not found", class_name);
- } else {
- zend_error(E_ERROR, "Class '%s' not found", class_name);
+ if (!silent) {
+ if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
+ zend_error(E_ERROR, "Interface '%s' not found", class_name);
+ } else {
+ zend_error(E_ERROR, "Class '%s' not found", class_name);
+ }
}
}
return NULL;

0 comments on commit eb0c56a

Please sign in to comment.