Php 7.1 - empty index operator array

As mentioned in http://php.net/manual/en/language.types.array.php

Note. Starting with PHP 7.1.0, using an empty index operator in a string causes a fatal error. Previously, a string was seamlessly converted to an array.

Can someone please tell me what this means with an example?

How will this affect my code?

Thank!

+4
source share
2 answers

In PHP <7.1:

$var = 'somestring';
$var[] = 'a'; # yields array with two elements ['somestring', 'a']

In PHP> = 7.1 this gives

Fatal error: Error on failure: [] operator is not supported for strings

+3
source

, , 7.1, - , : 3v4l.org/V5YJa

:

<?php
$rootbeer = '';
$rootbeer[] = 'T';
?>

PHP 7.1.0:

Fatal error: Uncaught Error: [] operator not supported for strings in your_file.php:4
Stack trace:
#0 {main}
  thrown in your_file.php on line 4

PHP PHP 7.0.1 .

, .

0

Source: https://habr.com/ru/post/1668830/


All Articles