Re: Re: 5.3 Namespace resolution rules suggestions

From: Date: Sat, 17 May 2008 00:10:00 +0000
Subject: Re: Re: 5.3 Namespace resolution rules suggestions
References: 1 2 3 4 5 6 7 8 9 10  Groups: php.internals 
Request: Send a blank email to internals+get-37690@lists.php.net to get a copy of this message
internal or user. But in namespace context I'll have to do something along the lines of: if (function_exists('json_encode')) { $encoded = json_encode($raw); } else { $encoded = ::json_encode($raw); }
What this code is supposed to do? If it's supposed to call namespace's json_encode in case global one is not defined, I see nothing wrong with it. If it is intended to call globally defined json_encode, then you just write ::json_encode, no ifs. The thing is you'd need to do it *ONLY* for json_encode, and only because you want to do something special with it. The principle is - common case is free, special cases are available, but for a "fee" - additional code.
The code is supposed to call the global internal json_encode() if it exists, and if not, call global user json_encode(). Without namespaces this is achieved in the following way: $encoded = json_encode($raw); // global user or global internal, doesn't matter, it's transparent. But inside a namespace, you'll need to do the above checks since internals and user functions don't resolve under the same rules.

« previous php.internals (#37690) next »