Posted 1 year, 6 months ago at 11:59 am by Jennifer. 0 comments

These comments were made three days ago. I think this is about the five thousandth time I have read these exact same sentiments. I’m not saying they are not true, but they are no longer original thoughts. Please stop attaching them to every single PHP-related post on the internet. It’s just something that everyone has heard and that is generally accepted common knowledge about PHP, so let’s just make it official:
First Theorem of PHP: PHP has a low barrier to entry, therefore it tends to attract a lot of inexperienced programmers.
Corollary to First Theorem of PHP: There is a lot of bad code written in PHP.
Posted 1 year, 7 months ago at 1:37 am by Jennifer. 2 comments
It was another frustrating night in the land of X. I went to install XDebug on my Leopard desktop and realized that PHP was no longer running. Interesting, since I know I had the Entropy.ch package installed and running a while back, so what happened? I figured something must have broken during an upgrade, so I poked around my machine and the Entropy user forums to try and resolve the problem.
I ended up reinstalling the Apache 2 version of the PHP 5 package, but found the assertion in the instructions that “PHP should now be up and running” to be incorrect. For some reason the installer script did not add the necessary line to the httpd.conf file, located at /etc/apache2/httpd.conf for me:
LoadModule php5_module /usr/local/php5/libphp5.so
I added this, restarted the server via the Sharing control panel, and… nothing. Now Apache wasn’t even running, despite the green light in the control panel. Running “apachectl configtest” revealed the following error:
httpd: Syntax error on line 116 of /private/etc/apache2/httpd.conf: Cannot load /usr/local/php5/libphp5.so into server: dlopen(/usr/local/php5/libphp5.so, 10): no suitable image found. Did find:\n\t/usr/local/php5/libphp5.so: no matching architecture in universal wrapper
Ah. OK. This was sounding familiar, and I followed the instructions in this forum post, Problem 2 and Problem 3, to get Apache to play nice with the Entropy package. After this I added the following lines to /usr/local/php5/lib/php.ini to point it to my XDebug .so, installed using “sudo pecl install xdebug”:
[xdebug]
zend_extension=/usr/local/php5/lib/php/extensions/no-debug-non-zts-20060613/xdebug.so
… and all was well. Or was it?
It seems that the problem here is that as part of Leopard, Apple switched over to using a 64-bit version of Apache 2. This was fine for them because their crippled bundled PHP 5 extension was updated to match. However, I was unaware of the issue and since I don’t use my desktop server much, it took me a long time to notice… during which time my PHP code was open to the world.
I want someone to blame here but the only person to blame is really myself… using non-standard packages, and not at least checking my external interfaces after a fairly major upgrade. Let this be a lesson: You never know when a seemingly simple upgrade is going to cause a huge security hole, even on your little home machine. Always take the responsibility of hosting seriously.
P.S. Marc Liyanage, where did you go? If you’re not going to update the packages anymore, please let someone take over for you… there are a lot of books and tutorials pointing to your packages…
Posted 1 year, 8 months ago at 1:20 am by Alvaro. 0 comments
I have always liked using a domain model to build a system. Most of the time, the easiest way to do that is to use some sort of Object-to-Relational mapping tool. I’ve been using Propel successfully for quite a while but I felt that there had to be a better approach. Later on I got to use hibernate (java orm) and I really liked the way it achieves “transparent” persistence. I’ve also seen similar results with SQLAlchemy (python) and LINQ (.NET) but never with a PHP ORM tool.
This transparency is a huge advantage that Data Mapper pattern has over Active Record implementations.
Although the PHP solutions are all MUCH better than not using an ORM at all, they all seem to have serious issues:
- All of them litter your entities (models) with properties and methods used for mapping and saving the entity to the database. This uses up memory and makes the output of “print_r” or “var_dump” full of stuff you don’t expect there.
- EZPDO (and probably others) doesn’t give you back a a real instance of your entity, instead it gives you some object that maps to it, breaking code that uses “instanceof” or type hints.
- Propel, Doctrine, and all Active Record implementations force your entities to extend from one of their classes, which prevents them from extending anything else. (I know there’s some workarounds for this).
- Propel requires complex criteria objects just to create a simple where clause such as ‘WHERE StatusID = 1 OR StatusID = 2′ (you could do this with Criteria::IN, I just couldn’t come up with a better example).
- They are all very big, which might be ok for a platform that holds its objects in memory across requests, but not PHP which re-instantiates them every time.
- Doctrine, EZPDO, and others encourage the use of their own form of SQL. While it may be handy in certain situations, I’ve only had to change database vendors in the middle of a project once in my career and the queries that are difficult to port are never the ones that an ORM would generate for you. They are usually the custom built ones that take advantage of vendor-specific features.
None of these are necessarily deal breakers, but I thought a new PHP ORM could do a much better job.
A few of months ago I started working on Outlet and a few days ago I released version 0.3. I believe it takes care of all of these issues very cleanly. It is unobtrusive and keeps your entities very clean. It provides just enough abstraction while staying very small, just a handful of classes. You can use regular SQL (call vendor-specific functions if needed) while still abstracting out the actual names of the tables and columns. It also feels very much like PHP which was an important objective.
Please check it out and let me know what you think. Keep in mind that it’s a work in progress and there are a lot of features I still would like to implement. That said, I started using it in some of my projects and I’m VERY pleased with the results.
Website: http://www.outlet-orm.org
It is open source (New BSD License) and I am very interested on user feedback. I set up the following google group (forum/mailing list) for anyone interested in submitting questions, bugs, feature requests, etc:
http://groups.google.com/group/outlet-orm
Alvaro