New PHP5-based Framework Project, PHP5 and Lack of Namespace Support, Among Other Things…
I have been spending way too much time programming with Python and Django. I was looking for something like Django but written for PHP5. I needed a way to go forward with my PHP-based projects since PHP4 will no longer receive updates next year.
Not satisfied with the PHP5 frameworks I found I decided to write my own (again). I looked at one particular candidate — [Picora ™: PHP Micro Framework][picora]. It’s small and focused on doing one thing: provide an MVC framework for PHP. While it has both qualities that I was looking for in an MVC framework there are a couple of issues that I found:
- it currently lacks an ActiveRecord implementation.
Note that the model() calls use a PHP ActiveRecord implementation which is not part of Picora, substitute with your own database logic for the time being.
- it makes the same (IMHO) mistake as CakePHP and Rails in that actions are mapped directly into methods in your Controller class without giving you the option of delegating it to a separate class. While there’s nothing wrong with this, I found that having all your actions in one big file becomes unwieldy when your project grows. Which was why I came up with [a modified action mapper for CakePHP][cakephp-sucks01].
So, for now Picora ™ doesn’t quite cut it for me yet. I began writing a new framework, based on some ideas I had from a year ago as well as taking a lot of inspiration from Django. I am writing the model class hierarchy based on Django’s excellent ORM. This will also be my first large project written using PHP5. Needless to say it has been pretty frustrating to find that PHP5 lacks namespace support. I was left wondering, “With PHP5, they practically went out and copied Java and yet they forgot to implement namespaces?!?”.
I did a search on Google for “php namespace support” and what I got was a depressing state of affairs for this important feature. It turns out that at the time, PHP5 namespace support is not a simple thing to implement and one of the major issues is the namespace separator. Maybe this is a testament to the fact that the PHP language is horribly broken an a multitude of places? Or maybe it’s because “design by committee” does not work? I found [one particularly entertaining post about the issue][shalosh] from 2005 and [a more recent posting][phpnamespaces] citing a [patch that implements namespaces for PHP6][phpnamespace-patch]. It looks like [namespace support will be in PHP6][zend-weekly]. I can only hope that this will be backported into a point release for PHP5.
Among other things I would like to see in PHP6:
- Closures or real anonymous functions at the very least. No,
create_function()does not count! - Inner classes.
- Inner functions.
- Make built-ins like
include(),include_once(),require(), andrequire_once()throw exceptions in addition to their original behavior. But it would really help to do away with the old*_error_handler()way of doing things.
These are just some of the features that I wish was in PHP, ever since PHP4.
[picora]: http://livepipe.net/projects/picora/ “Picora ™: PHP Micro Framework” [cakephp-sucks01]: http://abing.gotdns.com/posts/2006/cakephp-delegating-actions-to-separate-classes/ “CakePHP: Delegating Actions to Separate Classes” [shalosh]: http://blog.phpdoc.info/archives/27-+1-for-Shalosh-Nekudotayim.html “Shalosh Nekudotayim” [phpnamespaces]: http://www.gravitonic.com/blog/archives/000418.html “PHP Namespace Support” [phpnamespace-patch]: http://news.php.net/php.zend-engine.cvs/5894 “PHP6 Namespace Support Patch” [zend-weekly]: http://devzone.zend.com/article/2336-Zend-Weekly-Summaries-Issue-348 “Zend Weekly Summaries”

December 15th, 2007 at 10:08 pm
Namespaces are here in PHP5.3, however; the syntax is still not agreed, as well as some implementation issues are not cleared up. Here’s an article which might interest those waiting for namespaces being added to PHP: http://www.onphp5.com/article/60
May 30th, 2008 at 11:55 pm
Have you looked at PHPonTrax? it has a full ActiveRecord implementation. I have used it for many projects and it works just like rails does saves tons of time and makes coding much more enjoyable
May 31st, 2008 at 12:26 am
@John
Yes. I did take look at it. But unfortunately documentation was a bit lacking back then so I preferred not to comment on that. It seems there has been little progress made on this end as I just took a look at the API docs. It’s still spotty at best and it’s worse than having no documentation at all.
Come to think of it, I think ActiveRecord is overrated. The Django-style ORM is far easier to work with. Say what you want about it’s current lack of aggregation features. The less time I spend writing and debugging SQL, the better. So far from the PHPonTrax docs:
Uhm, sorry no. With Django, you write the model code in Python. Run manage.py syncdb and it automatically creates the database structure for you in the SQL dialect that your RDBMS of choice is using.
Since PHP5 has some form of class introspection already, I figured it would be feasible to clone the Django-style ORM in PHP5 as well. Alas, I had been sidetracked on another project and it’s currently shelved.
Sorry, again no. As Zed Shaw put it, “Rails is a Ghetto”. I’m don’t want to go into the details of this but suffice to say, whenever framework authors say that their framework is “just like rails” I tend to avoid them.
October 26th, 2008 at 4:18 pm
[...] the much anticipated (for me anyway) namespace support. I have documented my basic gripes about PHP elsewhere. So I won’t go rambling about them again. I was excited to hear about namespaces finally [...]