1
0
mirror of https://github.com/php/php-src.git synced 2026-04-28 02:33:17 +02:00

Fixed bug #42820 (defined() on constant with namespace prefixes tries to load class).

This commit is contained in:
Dmitry Stogov
2007-10-03 10:33:02 +00:00
parent 68055015eb
commit eb0c56ada1
6 changed files with 48 additions and 8 deletions
+2
View File
@@ -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).
+31
View File
@@ -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)
+1 -1
View File
@@ -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 {
+2
View File
@@ -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)
+4 -2
View File
@@ -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;
}
+8 -5
View File
@@ -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 @@ check_fetch_type:
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;