I think another problem with using @ is that it is done by the caller,
not the callee, so it doesn't allow functions like issetor() to be
implemented in userland without expecting every caller to do pass the
variable while silencing errors.

I also don't think the inconvenience is restricted to arrays. I
frequently use the idiom isset(X)?X:Y with X simply being a variable.
It's not just about silencing a notice, but about providing an
alternative/default value.

If doing the suppression of undefined notices be better if the ? was put after the opening square bracket, thereby removing the ambiguity (which I think would be more troublesome than you think)? $array[?"foo"]

Ben.



On 11/04/11 6:10 PM, Hannes Landeholm wrote:
@ is not convenient since it turns off error reporting for all errors. I
don't know how many times I've silenced a notice and got a blank page in my
face as a "thank you for accidentally silencing that fatal error too".

"Silent" is reserved for the purpose of the silence operator though @ so
using that as a keyword for something else would be confusing.


It just struck me that the ~real~ problem is that sometimes you want array
access that should define undefined indexes as being null (a good
placeholder for this purpose). How about (instead of the previously proposed
?? and isnotempty and whatnot) simply changing the "array access syntax" to
simply allow an optional "?" operator at the end signaling that the
condition where the index isn't defined isn't unexpected?

For example:

$value = isset($arr["foo"])? $arr["foo"]: null;
$value = isset($arr[$foo])? $arr[$foo]: null;

would be replaced with: (respectively)

$value = $arr["foo"?];
$value = $arr[$foo?];

it would also worked chained:

$value = $arr["foo"?]["bar"]["baz"?]

(if [foo] doesn't exist value will be null.. if [foo] exists [foo][bar] is
expected to exist but [foo][bar][baz] may or may not exist... if not, value
will once again be null)

This way it would only apply to array access which was a +1 for some.

This could also be extended too replace null with something different (by
allowing an expression after the "?" like "null" or "foo" . "bar") but I
think careful use-case research should be done to determine if it's really
needed first...

I realize this partially collides with the use of ? so it would be more
difficult to implement but it's far from impossible.. it just requires a
little ahead-parsing in brackets [] to know if the "?" is a ternary if or if
it's a "not exists is not undefined" operator (is the : missing or not?).
Otherwise "??" could simply be used instead or a completely different
operator...

~Hannes

On 11 April 2011 04:47, Stas Malyshev<smalys...@sugarcrm.com>  wrote:

Hi!

  @.


Note however it does not exactly "turn off" the warning, only changes it to
not reported. It's still generated and can be picked up by handlers, for
example.
--
Stanislav Malyshev, Software Architect
SugarCRM: http://www.sugarcrm.com/
(408)454-6900 ext. 227


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php




--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to