Le jeu. 5 mars 2015 à 23:20, Pascal Martin, AFUP <mailing@pascal-martin.fr>
a écrit :
> Le 23/02/2015 17:06, François Laupretre a écrit :
> > Starting the vote for https://wiki.php.net/rfc/array-to-string.
>
> Hi,
>
> We talked about this with other people at AFUP and a great majority of
> us agrees that the current behavior of array to strings conversions is
> not quite useful
Nor are all the following operations:
$useOfUnexistingVariableIsOkToContinueExecution = $variableNotSet;
$obj = new stdClass();
$useOfUnexistingPropertyIsOkToContinueExecution = $obj->notFound;
$computingWithObjectIsOkToContinueExecution = 42 + new stdClass();
$array = array(42);
$useOfUnexistingOffsetIsOkToContinueExecution = $array[42];
$int = 42;
$usingANumberAsAnArrayIsFineNoNotice = $int["foo"];
$null = NULL;
$usingANonObjectAsAnObjectIsOkToContinueExecution = $null->notAnObject;
$resource = fopen("/etc/hosts", "r");
$resourceToStringConversionIsOkToContinueExecution = (string) $resource;
Running the above would produce:
PHP Notice: Undefined variable: variableNotSet in - on line 2
Notice: Undefined variable: variableNotSet in - on line 2
PHP Notice: Undefined property: stdClass::$notFound in - on line 5
Notice: Undefined property: stdClass::$notFound in - on line 5
PHP Notice: Object of class stdClass could not be converted to int in - on
line 7
Notice: Object of class stdClass could not be converted to int in - on line
7
PHP Notice: Undefined offset: 42 in - on line 10
Notice: Undefined offset: 42 in - on line 10
PHP Notice: Trying to get property of non-object in - on line 16
Notice: Trying to get property of non-object in - on line 16
-- and, for several of us, when we started getting
> notices with PHP 5.4, it actually showed us there were bugs in our
> applications.
>
Which confirms that turning notices 'On' would allow anyone to fix code
that may seems suspect.
> So, we are +1 on this.
>
> Basically, even if notices are already bringing some useful information,
> we feel being more "strict" and "explicit" than that might help, here.
>
Why suddenly changing that specific notice, without deprecation, to one
that stop the execution and without "opt-in" for it? (and according to the
patch, only in some "array to string conversion", not all?)
I'm about to post another suggestion in a fork of this discussion which
might fit anyone, stay tuned!
Cheers,
Patrick