l want to point out that way in which notices and warnings are triggered
when concerning operators, is also inconsistent.
Sometimes a check is done by the function of the operator (or a deeper
function). Other times the operator will simply cast the operand and the
casting produces a notice, warning or error.
As an example; The concatenation operator will implicitly cast anything to
a string. Explicitly casting it has no effect
[ ] . 'abc'; // Notice: Array to string conversion
(string)[ ] . 'abc'; // Notice: Array to string conversion
But arithmetic operators will do a check. Explicitly casting will remove
any warning or error
[ ] * 10; // Fatal error: Unsupported operand types
(int)[ ] * 10; // 0
"22 bikes" * 10; // Notice: A non well formed numeric value encountered
(int)"22 bikes" * 10; // 220
To some extent, the inconsistent error levels come from a different
approach. Even more, there is a big difference between types that can are
cast silently to a non-sensical value and types where any type of warning
or error is given, for seemingly no apparent reason.
Changing the warning levels without addressing this issue doesn't make a
whole lot of sense.
- Arnold
In the past I suggested operators like
??++
??+=
for this purpose.
But the [? $key] is even better, because it makes it explicit which array
keys we expect to already exist and which we don't.
$var[$k0][? $k1][? $k2]++;
This is great but the second "?" is redundant isn't it?
Tekst uit oorspronkelijke berichten weergeven