Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

fix bug #53432 (Assignment via string index access on an empty string converts to array) #463

Closed
wants to merge 1 commit into from

3 participants

@bixuehujin

see https://bugs.php.net/bug.php?id=53432

  • Assignment via string index on an empty string will produce a Illegal string offset
    warning now.

  • Split Zend/tests/indexing_001.phpt into multiple files for readability improvement.

@bixuehujin bixuehujin fix bug #53432 (Assignment via string index access on an empty string…
… converts to array)

see https://bugs.php.net/bug.php?id=53432

- Assignment via string index on an empty string will produce a Illegal string offset
warning now.

- Split Zend/tests/indexing_001.phpt into multiple files for readability improvement.
2c67769
@smalyshev
Owner

This is a serious change in how conversions work, so I don't think it can be done in 5.x

@yohgaki

May be PHP 6?
We are discussing this issue on internals@php.net. If you would like to discuss, please subscribe the list.

@bixuehujin bixuehujin closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 20, 2013
  1. @bixuehujin

    fix bug #53432 (Assignment via string index access on an empty string…

    bixuehujin authored
    … converts to array)
    
    see https://bugs.php.net/bug.php?id=53432
    
    - Assignment via string index on an empty string will produce a Illegal string offset
    warning now.
    
    - Split Zend/tests/indexing_001.phpt into multiple files for readability improvement.
This page is out of date. Refresh to see the latest.
View
214 Zend/tests/indexing_001.phpt
@@ -1,214 +0,0 @@
---TEST--
-Indexing - various special cases.
---FILE--
-<?php
-echo "*** Indexing - Testing value assignment with key ***\n";
-$array=array(1);
-$testvalues=array(null, 0, 1, true, false,'',' ',0.1,array());
-
-foreach ($testvalues as $testvalue) {
- $testvalue['foo']=$array;
- var_dump ($testvalue);
-}
-echo "\n*** Indexing - Testing reference assignment with key ***\n";
-
-$testvalues=array(null, 0, 1, true, false,'',0.1,array());
-
-foreach ($testvalues as $testvalue) {
- $testvalue['foo']=&$array;
- var_dump ($testvalue);
-}
-echo "*** Indexing - Testing value assignment no key ***\n";
-$array=array(1);
-$testvalues=array(null, 0, 1, true, false,'',0.1,array());
-
-foreach ($testvalues as $testvalue) {
- $testvalue[]=$array;
- var_dump ($testvalue);
-}
-echo "\n*** Indexing - Testing reference assignment no key ***\n";
-
-$testvalues=array(null, 0, 1, true, false,'',0.1,array());
-
-foreach ($testvalues as $testvalue) {
- $testvalue[]=&$array;
- var_dump ($testvalue);
-}
-
-
-echo "\nDone";
-?>
---EXPECTF--
-*** Indexing - Testing value assignment with key ***
-array(1) {
- ["foo"]=>
- array(1) {
- [0]=>
- int(1)
- }
-}
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-int(0)
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-int(1)
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-bool(true)
-array(1) {
- ["foo"]=>
- array(1) {
- [0]=>
- int(1)
- }
-}
-array(1) {
- ["foo"]=>
- array(1) {
- [0]=>
- int(1)
- }
-}
-
-Warning: Illegal string offset 'foo' in %s on line %d
-
-Notice: Array to string conversion in %s on line %d
-string(1) "A"
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-float(0.1)
-array(1) {
- ["foo"]=>
- array(1) {
- [0]=>
- int(1)
- }
-}
-
-*** Indexing - Testing reference assignment with key ***
-array(1) {
- ["foo"]=>
- &array(1) {
- [0]=>
- int(1)
- }
-}
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-int(0)
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-int(1)
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-bool(true)
-array(1) {
- ["foo"]=>
- &array(1) {
- [0]=>
- int(1)
- }
-}
-array(1) {
- ["foo"]=>
- &array(1) {
- [0]=>
- int(1)
- }
-}
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-float(0.1)
-array(1) {
- ["foo"]=>
- &array(1) {
- [0]=>
- int(1)
- }
-}
-*** Indexing - Testing value assignment no key ***
-array(1) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
-}
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-int(0)
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-int(1)
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-bool(true)
-array(1) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
-}
-array(1) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
-}
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-float(0.1)
-array(1) {
- [0]=>
- array(1) {
- [0]=>
- int(1)
- }
-}
-
-*** Indexing - Testing reference assignment no key ***
-array(1) {
- [0]=>
- &array(1) {
- [0]=>
- int(1)
- }
-}
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-int(0)
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-int(1)
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-bool(true)
-array(1) {
- [0]=>
- &array(1) {
- [0]=>
- int(1)
- }
-}
-array(1) {
- [0]=>
- &array(1) {
- [0]=>
- int(1)
- }
-}
-
-Warning: Cannot use a scalar value as an array in %s on line %d
-float(0.1)
-array(1) {
- [0]=>
- &array(1) {
- [0]=>
- int(1)
- }
-}
-
-Done
View
60 Zend/tests/indexing_bool_to_array.phpt
@@ -0,0 +1,60 @@
+--TEST--
+Indexing -- Convert boolean variable to array
+--FILE--
+<?php
+$value = array(1);
+require 'indexing_testing.inc';
+
+run_test(true, $value, true);
+run_test(false, $value, true);
+
+run_test_ref(true, $value, true);
+run_test_ref(false, $value, true);
+
+run_test(true, $value, false);
+run_test(false, $value, false);
+
+run_test_ref(true, $value, false);
+run_test_ref(false, $value, false);
+
+?>
+--EXPECTF--
+Warning: Cannot use a scalar value as an array in %s on line %d
+bool(true)
+array(1) {
+ ["foo"]=>
+ array(1) {
+ [0]=>
+ int(1)
+ }
+}
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+bool(true)
+array(1) {
+ ["foo"]=>
+ &array(1) {
+ [0]=>
+ int(1)
+ }
+}
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+bool(true)
+array(1) {
+ [0]=>
+ array(1) {
+ [0]=>
+ int(1)
+ }
+}
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+bool(true)
+array(1) {
+ [0]=>
+ &array(1) {
+ [0]=>
+ int(1)
+ }
+}
View
26 Zend/tests/indexing_float_to_array.phpt
@@ -0,0 +1,26 @@
+--TEST--
+Indexing -- Convert float variable to array
+--FILE--
+<?php
+require 'indexing_testing.inc';
+$value = array(1);
+
+run_test(0.1, $value, true, false);
+run_test(0.1, $value, true, true);
+
+run_test(0.1, $value, false, false);
+run_test(0.1, $value, false, true);
+
+?>
+--EXPECTF--
+Warning: Cannot use a scalar value as an array in %s on line %d
+float(0.1)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+float(0.1)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+float(0.1)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+float(0.1)
View
44 Zend/tests/indexing_integer_to_array.phpt
@@ -0,0 +1,44 @@
+--TEST--
+Indexing -- Convert integer variable to array
+--FILE--
+<?php
+require 'indexing_testing.inc';
+$value = array(1);
+
+run_test(1, $value, true);
+run_test(0, $value, true);
+
+run_test_ref(1, $value, true);
+run_test_ref(0, $value, true);
+
+run_test(1, $value, false);
+run_test(0, $value, false);
+
+run_test_ref(1, $value, false);
+run_test_ref(0, $value, false);
+
+?>
+--EXPECTF--
+Warning: Cannot use a scalar value as an array in %s on line %d
+int(1)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+int(0)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+int(1)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+int(0)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+int(1)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+int(0)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+int(1)
+
+Warning: Cannot use a scalar value as an array in %s on line %d
+int(0)
View
45 Zend/tests/indexing_null_to_array.phpt
@@ -0,0 +1,45 @@
+--TEST--
+Indexing -- Convert null to array
+--FILE--
+<?php
+require 'indexing_testing.inc';
+$value = array(1);
+
+run_test(null, $value, true);
+
+run_test_ref(null, $value, true);
+
+run_test(null, $value, false);
+
+run_test_ref(null, $value, false);
+
+?>
+--EXPECTF--
+array(1) {
+ ["foo"]=>
+ array(1) {
+ [0]=>
+ int(1)
+ }
+}
+array(1) {
+ ["foo"]=>
+ &array(1) {
+ [0]=>
+ int(1)
+ }
+}
+array(1) {
+ [0]=>
+ array(1) {
+ [0]=>
+ int(1)
+ }
+}
+array(1) {
+ [0]=>
+ &array(1) {
+ [0]=>
+ int(1)
+ }
+}
View
24 Zend/tests/indexing_string_to_array.phpt
@@ -0,0 +1,24 @@
+--TEST--
+Indexing -- Convert string to array
+--FILE--
+<?php
+require 'indexing_testing.inc';
+$value = array(1);
+
+run_test('', $value, true);
+run_test(' bar', $value, true);
+run_test('', $value, false);
+
+?>
+--EXPECTF--
+Warning: Illegal string offset 'foo' in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+string(1) "A"
+
+Warning: Illegal string offset 'foo' in %s on line %d
+
+Notice: Array to string conversion in %s on line %d
+string(5) "A bar"
+
+Fatal error: [] operator not supported for strings in %s on line %d
View
24 Zend/tests/indexing_testing.inc
@@ -0,0 +1,24 @@
+<?php
+function run_test($variable, $value, $withKey) {
+ if ($variable !== 'undefined') {
+ $testing = $variable;
+ }
+ if ($withKey) {
+ $testing['foo'] = $value;
+ }else {
+ $testing[] = $value;
+ }
+ var_dump($testing);
+}
+
+function run_test_ref($variable, &$value, $withKey) {
+ if ($variable !== 'undefined') {
+ $testing = $variable;
+ }
+ if ($withKey) {
+ $testing['foo'] = &$value;
+ }else {
+ $testing[] = &$value;
+ }
+ var_dump($testing);
+}
View
43 Zend/tests/indexing_undefined_to_array.phpt
@@ -0,0 +1,43 @@
+--TEST--
+Indexing -- Convert undefined variable to array
+--FILE--
+<?php
+require 'indexing_testing.inc';
+$value = array(1);
+
+run_test('undefined', $value, true);
+run_test_ref('undefined', $value, true);
+
+run_test('undefined', $value, false);
+run_test_ref('undefined', $value, false);
+
+?>
+--EXPECTF--
+array(1) {
+ ["foo"]=>
+ array(1) {
+ [0]=>
+ int(1)
+ }
+}
+array(1) {
+ ["foo"]=>
+ &array(1) {
+ [0]=>
+ int(1)
+ }
+}
+array(1) {
+ [0]=>
+ array(1) {
+ [0]=>
+ int(1)
+ }
+}
+array(1) {
+ [0]=>
+ &array(1) {
+ [0]=>
+ int(1)
+ }
+}
View
3  Zend/zend_execute.c
@@ -1133,9 +1133,6 @@ static void zend_fetch_dimension_address(temp_variable *result, zval **container
case IS_STRING: {
zval tmp;
- if (type != BP_VAR_UNSET && Z_STRLEN_P(container)==0) {
- goto convert_to_array;
- }
if (dim == NULL) {
zend_error_noreturn(E_ERROR, "[] operator not supported for strings");
}
Something went wrong with that request. Please try again.