On Feb 1, 2008 9:06 PM, Stanislav Malyshev <[EMAIL PROTECTED]> wrote:
> > Stupid question, who actually checks for E_* in his code at runtime
> > after having called such functions? Not me and I would hate to. It
> > sounds to me like a perfect exception use case. As this function can
>
> General policy in PHP as far as I know is that non-OO functions do not
> do exceptions.
>
> > return nearly everything scalar we have (boolean, string, null,
> > integer,...) we can't use our normal "returns FALSE on failure".
>
> This function can return only a string, but I'm not sure returning false
> if somewhere in some value deep down your data is some bad utf-8 is
> warranted. It is doable, though, but I'm afraid most of current code
> never check for return of json_encode() so they are in for big surprises
>   when json_encode won't produce valid JSON.

Oh right, I thought about/read json_decode. But the idea is the same
yes. Not checking return values is a very bad habit, I can't count how
many times I saw codes dying miserably only because they don't check
returns values. Would it make sense to use exception for such cases?
Aka to change our policy? I'm not an excpeption fan, but these cases
are good examples of exception usages. We can invent a meta type
"error" but it would be rather confusing  ;)

-- 
Pierre
http://blog.thepimp.net | http://www.libgd.org

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

Reply via email to