]> granicus.if.org Git - php/commitdiff
Report unknown variables passed to compact()
authorGabriel Caruso <carusogabriel34@gmail.com>
Fri, 30 Mar 2018 20:44:31 +0000 (17:44 -0300)
committerChristoph M. Becker <cmbecker69@gmx.de>
Tue, 19 Jun 2018 10:50:15 +0000 (12:50 +0200)
UPGRADING
ext/standard/array.c
ext/standard/tests/array/bug69198.phpt
ext/standard/tests/array/compact.phpt
ext/standard/tests/array/compact_basic.phpt
ext/standard/tests/array/compact_variation2.phpt

index bd36c74cf0f3682781fb7149b40189b4a0253608..ce0d4a852f5b9c4a32c752554802632e1ea9677e 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -83,6 +83,7 @@ SimpleXML:
     treated as integers unconditionally.
 
 Standard:
+  . Undefined variables passed to compact() will now be reported as a notice.
   . getimagesize() and related functions now report the mime type of BMP images
          as image/bmp instead of image/x-ms-bmp, since the former has been registered
                with the IANA (see RFC 7903).
index eb89c7061b613ac4813db37fd1c1af58e2a9e54a..c2fb36e7ca49da5a8fdb9b2bcab841a7e90161e4 100644 (file)
@@ -2598,14 +2598,15 @@ static void php_compact_var(HashTable *eg_active_symbol_table, zval *return_valu
                        ZVAL_DEREF(value_ptr);
                        ZVAL_COPY(&data, value_ptr);
                        zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
-               }
-               if (zend_string_equals_literal(Z_STR_P(entry), "this")) {
+               } else if (zend_string_equals_literal(Z_STR_P(entry), "this")) {
                        zend_object *object = zend_get_this_object(EG(current_execute_data));
                        if (object) {
                                GC_ADDREF(object);
                                ZVAL_OBJ(&data, object);
                                zend_hash_update(Z_ARRVAL_P(return_value), Z_STR_P(entry), &data);
                        }
+               } else {
+                       php_error_docref(NULL, E_NOTICE, "Undefined variable: %s", ZSTR_VAL(Z_STR_P(entry)));
                }
        } else if (Z_TYPE_P(entry) == IS_ARRAY) {
            if (Z_REFCOUNTED_P(entry)) {
index 3faa5aac1c6520c746f6a30a74ffd7a98bb3df71..96a0f9a963262f1fd5b1c69e38e0f1a836ecd760 100644 (file)
@@ -7,7 +7,9 @@ if (false) {
 }
 $result = compact('willNeverBeDefined');
 var_dump($result, empty($result), $result === array(), empty($willNeverBeDefined));
---EXPECT--
+?>
+--EXPECTF--
+Notice: compact(): Undefined variable: willNeverBeDefined in %s on line %d
 array(0) {
 }
 bool(true)
index e264be1977c4eb003ac1e9bdc9ce510fb9d026b7..d18f3d83e95ec5e58273dd1e9411c83245771a21 100644 (file)
@@ -12,7 +12,8 @@ $location_vars = array("c\\u0327ity", "state");
 $result = compact("event", $location_vars);
 var_dump($result);
 ?>
---EXPECT--
+--EXPECTF--
+Notice: compact(): Undefined variable: c\u0327ity in %s on line %d
 array(2) {
   ["event"]=>
   string(8) "SIGGRAPH"
index 4d9aab068977f019dcdbd7ecf89057b935d934c2..c71215fe1b17b71b970b19139fe6a9e508a3d0dc 100644 (file)
@@ -1,11 +1,11 @@
 --TEST--
-Test compact() function : basic functionality 
+Test compact() function : basic functionality
 --FILE--
 <?php
 /* Prototype  : proto array compact(mixed var_names [, mixed ...])
- * Description: Creates a hash containing variables and their values 
+ * Description: Creates a hash containing variables and their values
  * Source code: ext/standard/array.c
- * Alias to functions: 
+ * Alias to functions:
  */
 
 /*
@@ -34,7 +34,7 @@ var_dump (compact(array("g")));
 
 echo "Done";
 ?>
---EXPECT--
+--EXPECTF--
 *** Testing compact() : basic functionality ***
 array(6) {
   ["a"]=>
@@ -80,6 +80,8 @@ array(0) {
 }
 array(0) {
 }
+
+Notice: compact(): Undefined variable: g in %s on line %d
 array(0) {
 }
-Done
\ No newline at end of file
+Done
index 91806bc0c87681e28c5194616f51fc5818c0ae30..8ca5020d6d7f0aae1dc1579444af40ca88ea7576 100644 (file)
@@ -23,18 +23,22 @@ f();
 
 ?>
 ==Done==
---EXPECT--
+--EXPECTF--
 *** Testing compact() : usage variations  - variables outside of current scope ***
+
+Notice: compact(): Undefined variable: a in %s on line %d
 array(2) {
   ["b"]=>
   string(3) "f.b"
   ["c"]=>
   string(3) "f.c"
 }
+
+Notice: compact(): Undefined variable: a in %s on line %d
 array(2) {
   ["b"]=>
   string(3) "f.b"
   ["c"]=>
   string(3) "f.c"
 }
-==Done==
\ No newline at end of file
+==Done==