Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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

… to load class).
  • Loading branch information...
commit eb0c56ada1e2d6f4155c32c23cea56502de7751e 1 parent 6805501
authored October 03, 2007
2  NEWS
@@ -35,6 +35,8 @@ PHP                                                                        NEWS
35 35
 - Improved and cleaned CGI code. FastCGI is now always enabled and can not be
36 36
   disabled. See sapi/cgi/CHANGES for more details. (Dmitry)
37 37
 
  38
+- Fixed bug #42820 (defined() on constant with namespace prefixes tries to load
  39
+  class). (Dmitry)
38 40
 - Fixed bug #42798 (__autoload() not triggered for classes used in method
39 41
   signature). (Dmitry)
40 42
 - Fixed bug #42657 (ini_get() returns incorrect value when default is NULL).
31  Zend/tests/bug42820.phpt
... ...
@@ -0,0 +1,31 @@
  1
+--TEST--
  2
+Bug #42820 (defined() on constant with namespace prefixes tries to load class)
  3
+--FILE--
  4
+<?php
  5
+namespace ns;
  6
+const ok = 0;
  7
+class foo {
  8
+	const ok = 0;
  9
+}
  10
+var_dump(defined('ns::ok'));
  11
+var_dump(defined('ns::bug'));
  12
+var_dump(defined('::ns::ok'));
  13
+var_dump(defined('::ns::bug'));
  14
+var_dump(defined('ns::foo::ok'));
  15
+var_dump(defined('ns::foo::bug'));
  16
+var_dump(defined('::ns::foo::ok'));
  17
+var_dump(defined('::ns::foo::bug'));
  18
+var_dump(defined('ns::bar::bug'));
  19
+var_dump(defined('::ns::bar::bug'));
  20
+--EXPECT--
  21
+bool(true)
  22
+bool(false)
  23
+bool(true)
  24
+bool(false)
  25
+bool(true)
  26
+bool(false)
  27
+bool(true)
  28
+bool(false)
  29
+bool(false)
  30
+bool(false)
  31
+
2  Zend/zend_builtin_functions.c
@@ -545,7 +545,7 @@ ZEND_FUNCTION(defined)
545 545
 	}
546 546
 	
547 547
 	convert_to_string_ex(var);
548  
-	if (zend_get_constant_ex(Z_STRVAL_PP(var), Z_STRLEN_PP(var), &c, NULL, 0 TSRMLS_CC)) {
  548
+	if (zend_get_constant_ex(Z_STRVAL_PP(var), Z_STRLEN_PP(var), &c, NULL, ZEND_FETCH_CLASS_SILENT TSRMLS_CC)) {
549 549
 		zval_dtor(&c);
550 550
 		RETURN_TRUE;
551 551
 	} else {
2  Zend/zend_compile.h
@@ -597,9 +597,11 @@ int zendlex(znode *zendlval TSRMLS_DC);
597 597
 #define ZEND_FETCH_CLASS_AUTO		5
598 598
 #define ZEND_FETCH_CLASS_INTERFACE	6
599 599
 #define ZEND_FETCH_CLASS_STATIC		7
  600
+#define ZEND_FETCH_CLASS_MASK        0x0f
600 601
 #define ZEND_FETCH_CLASS_RT_NS_CHECK 0x20
601 602
 #define ZEND_FETCH_CLASS_RT_NS_NAME  0x40
602 603
 #define ZEND_FETCH_CLASS_NO_AUTOLOAD 0x80
  604
+#define ZEND_FETCH_CLASS_SILENT      0x0100
603 605
 
604 606
 /* variable parsing type (compile-time) */
605 607
 #define ZEND_PARSED_MEMBER				(1<<0)
6  Zend/zend_constants.c
@@ -274,7 +274,7 @@ ZEND_API int zend_get_constant_ex(char *name, uint name_len, zval *result, zend_
274 274
 	if (name[0] == ':' && name[1] == ':') {
275 275
 		name += 2;
276 276
 		name_len -= 2;
277  
-		flags = 0;
  277
+		flags &= ZEND_FETCH_CLASS_SILENT;
278 278
 	}
279 279
 
280 280
 	
@@ -374,7 +374,9 @@ ZEND_API int zend_get_constant_ex(char *name, uint name_len, zval *result, zend_
374 374
 					retval = 1;
375 375
 					return zend_get_constant(name, name_len, result TSRMLS_CC);
376 376
 				}
377  
-				zend_error(E_ERROR, "Class '%s' not found", class_name);
  377
+				if ((flags & ZEND_FETCH_CLASS_SILENT) == 0) {
  378
+					zend_error(E_ERROR, "Class '%s' not found", class_name);
  379
+				}
378 380
 			}
379 381
 			retval = 0;
380 382
 		}
13  Zend/zend_execute_API.c
@@ -1513,8 +1513,9 @@ zend_class_entry *zend_fetch_class(const char *class_name, uint class_name_len,
1513 1513
 	zend_class_entry **pce;
1514 1514
 	int use_autoload = (fetch_type & ZEND_FETCH_CLASS_NO_AUTOLOAD) == 0;
1515 1515
 	int rt_ns_check  = (fetch_type & ZEND_FETCH_CLASS_RT_NS_CHECK)  ? 1 : 0;
  1516
+	int silent       = (fetch_type & ZEND_FETCH_CLASS_SILENT) != 0;
1516 1517
 
1517  
-	fetch_type = fetch_type & ~ZEND_FETCH_CLASS_NO_AUTOLOAD;
  1518
+	fetch_type &= ZEND_FETCH_CLASS_MASK;
1518 1519
 check_fetch_type:
1519 1520
 	switch (fetch_type) {
1520 1521
 		case ZEND_FETCH_CLASS_SELF:
@@ -1568,10 +1569,12 @@ zend_class_entry *zend_fetch_class(const char *class_name, uint class_name_len,
1568 1569
 			    zend_lookup_class_ex(class_name, class_name_len, 1, &pce TSRMLS_CC)==SUCCESS) {
1569 1570
 				return *pce;
1570 1571
 			}
1571  
-			if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
1572  
-				zend_error(E_ERROR, "Interface '%s' not found", class_name);
1573  
-			} else {
1574  
-				zend_error(E_ERROR, "Class '%s' not found", class_name);
  1572
+			if (!silent) {
  1573
+				if (fetch_type == ZEND_FETCH_CLASS_INTERFACE) {
  1574
+					zend_error(E_ERROR, "Interface '%s' not found", class_name);
  1575
+				} else {
  1576
+					zend_error(E_ERROR, "Class '%s' not found", class_name);
  1577
+				}
1575 1578
 			}
1576 1579
 		}
1577 1580
 		return NULL;

0 notes on commit eb0c56a

Please sign in to comment.
Something went wrong with that request. Please try again.