Re: Reply on "Who is using namespaces in PHP already?"
| From: | Jochem Maas | Date: | Tue, 16 Sep 2008 10:12:05 +0000 |
| Subject: | Re: Reply on "Who is using namespaces in PHP already?" | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-40528@lists.php.net to get a copy of this message | ||
Vesselin Kenashkov schreef:
We had no issues related to the namespaces (well we found & reported some minor bugs, but not related to the namespaces).to be clear, your not using namespaced functions or constants? and your not using any classes that are not namespaced? how are you handling usage of internal classes?
Of course we have one namespace per file, having the file structure following the namespace structure. As well, as Karsten mentions, converting some_class_name_new to some::class::name::new is not an option. We had no issues with the name resolution and no confusion so far on how to use the namespaces. In fact, we have a complex autoload procedure that follows the directory/namespace hierarchy to load/create (yes we generate some) classes. No issues with the autoload so far. Just one note: you should not throw Exceptions during the all autoload process, not just the __autoload function.true, although you can actually successfully throw an exception from within autoload to the scope that triggered the autoload ... it's a bit of a WTF, there is also a workaround that uses eval to generate a class (when the class isn't found) that does nothing except throw exceptions upon init, static calls etc ... so that the code trying to use the non-existent class does actually get a class of the given name but using it *always* results in an exception (e.g. AutoLoadException or UnknownClassException)
I haven't checked the releases in the last month so this might have changed. Besides the namespaces, our internal framework uses in it fundamentals the Late Static Binding (for creating singletons and providing the static method get_instance ).are you in a position to offer a few bits of example code to demostrate how/what your doing with respect to namespaces. I'm in the process of gathering material in order to compile a 'best practices' guide for namespaces ... I believe that there is a strong need to educate users in general on how/what/why to do things a certain way with namespaces (I include myself in that group of users!) ... maybe some of your implementation details could help educate others?
In overall I can say that php 5.3 is highly anticipated (both because of the namespaces and LSB). I'm reading the ongoing discussions and proposals for support for multiple namespaces per file but this I think will delay 5.3. My opinion is that php 5.3. has to be finally released even with limited support for namespaces. It can be followed immediately with another release with the extended namespace support (this way many users will switch to namespace support although some CMS/frameworks will not because for optimization reasons they combine files). 5.3 was delayed enough already...your using alpha software in production, understandbly your hoping nothing changes and that it's released asap. but really your on the bleeding edge, some blood is to be expected. I don't actually think either LSB or namespaces is that highly anticipated in the larger arena, I think users like yourself and I are in a minority in that respect. I also think that uptake of these features will be modest at best, many developers/projects require that their code runs on older versions (even to the point of still supporting php4) which makes applying these new features impossible for them.
Vesselin Kenashkov On Tue, Sep 16, 2008 at 2:10 AM, Jochem Maas <jochem@iamjochem.com> wrote:Vesselin Kenashkov schreef:Hi, At our company the majority of the projects in the last 4 months are using namespaces (we can afford using dev version of php, because we host the projects). Just to add my +1 into the count.care to elaborate? what are your experiences? have you run into any trouble? have you developed a list of do's and dont's? (as Karsten has)Vesselin Kenashkov On Mon, Sep 15, 2008 at 5:26 PM, Karsten Dambekalns <karsten@typo3.orgwrote:Hi.Lukas asked on his Blog, so here goes my answer. We switched to namespaces last week for FLOW3 and all related packages. See http://forge.typo3.org/repositories/revision/21/1210 for the needed changes and http://forge.typo3.org/wiki/flow3-overview/Notes_on_using_PHP_namespacesfor some notes on the implications. Currently we don't have any problems with use statements, as we still have fully qualified names almost everywhere, thus autoloading works as expected. Still, looking into the future I'd love to see an enhancement as proposed by Greg in http://marc.info/?l=php-internals&m=121527668606247 plus some way to get rid of having to use single classes if I could use some wildcard instead. Regards, Karsten -- Karsten Dambekalns Gimme Five! http://typo3.org/gimmefive