This question of PHP vs Rails comes up more than enough, and it
needs to be seriously addressed.
I used to work for a company specializing in PHP web development.
the end of my employment I was advocating the development of a PHP
based off of Rails and Cake (the open source PHP framework inspired by
Rails). I spend a little over 2 months putting together a prototype of
PHP like Rails. The endeavor has illuminated many fine points of this
distinction. In an attempt to answer the question of “Why would anyone
prefer PHP over Rails or visa versa?”, I present the following with an
emphasis on the implementation.
- Ruby over PHP
a) the PHP parser is too inflexible.
- The biggest caveat of PHP is that methods cannot be added on the fly
classes without compiling in a special library called runkit, located at
http://php.net/manual/en/ref.runkit.php. In other words: classes are
upon definition. If one wants to create an active_record like ORM then
is determined to include runkit when compiling the php parser or write
definition files to the hard drive on the fly.
b) PHP references are kludged in PHP4. It is common to pass by
C and C++ in order to save memory and utilize return value optimization.
my implementation of a PHP version of Rails I ended up splitting an
“ActiveRecord” into two classes: a Factory and an Object class. Each
instance would have as a data-member a reference to its Factory in an
to not duplicate the sql_generation methods. The Factory instance would
also contain all of the instances of its objects, hoping that each
would simply be a reference into the Factories container. As a bug,
the objects filled up memory so did the reference count… I belive
fixed in PHP5.
c) is possibly two counts: an overbearing responsibility upon global
in PHP, and the fact that PHP’s object.c class is designed to do
everything. Addressing the later first, I acknowledge that both PHP and
Ruby have base object classes. Their distinction is that, in Ruby the
object class is designed to provide methods to all inherited objects,
whereas in PHP the object class is designed to also contain data: for
example, there is a minimal distinction between PHP’s array data
and PHP’s object data structures; the two are almost equivocal and it is
therefore tiresome to distinguish (in code) between objects, arrays and
hashes (what PHPers call associative arrays). As a result there is a
type checking in PHP. I suspect that this equivocation is the main
for the plethora of global methods.
d) finally, I find that the simplicity of Ruby’s to_s style methods put
language above and beyond both Java and PHP. However, I fear that I am
expert enough to defend this adequately.
It may not be hidden that I loath PHP, and mainly because of the
©. However I also feel that PHP has its place. Let me elaborate.
- PHP over Ruby
a) PHP’s learning curve is close to nothing. Switching mentalities
Java, C and C++ to PHP is admirably easy. Most CS graduate students
have experience in the three canons of development languages listed
The better education includes experience in Scheme, or Lisp, for the
breadth of syntactic understanding. Most of us do acknowledge the
importance of pseudo code and see that all implementations are just
divergent from that initial “pseudo” logic. However, as a precondition,
some development environments cannot cater to a heightened sense of
programesque. In other words, there is a need for non-CS people to
web based programs and PHP satisfies that need.
I do, in an elitist fashion, consent that Ruby is the superior language
PHP. However I also realize that PHP satisfies a niche that is
for Ruby to semantically attain (however it is certainly possible to
a php (read global) like semantic).
- A little bit about Rails
Insofar as I can tell, PHP has another upper hand over Rails/Ruby, and
is the support PHP has within Windows Servers. One of the major
encountered in a PHP version of Rails was the esteem of the
Windows servers are mainly processed based (as opposed to thread based),
therefore prefer to spawn another parser for each request rather than
an error in a thread. PHP has done an awesome job making a fastcgi port
their parser. PHP’s fastcgi is oriented towards ever .php file rather
just one dispatcher. I would love to see Ruby duplicate this effort in
their own fcgi such that it can run different dispatch.fcgi’s.
Such a framework as Rails is possible in PHP, however because of the
implementation restrictions of PHP, developing a “Rails” for it should
tiresome, if not mind wracking. However, I do not think there should be
Rails equivalent developed for PHP solely because the language fits a
different niche; if I were to describe it, I would say that it is the
easy and dirty.