From ruby -> php. What tools should I be using?

For work-related reasons, I'm intending to learn php after a few years of ruby hacking.

What I'm wondering, are what are the best and most-adopted coding tools - what does a smart modern php coding ecosystem look like? (I'm on ubuntu if that makes a difference, and I was intending to dive into symfony after some initial mucking around).

Are there (reasonably well supported/adopted) equivalents to:

rvm (managing interpreter versions and library sets)

bundler (dependency management)

rake (do people just use make?)

rubygems (should I be using php-pear or composer? something else?)

what testing libraries to use? (simpletest?)

what good/popular templating/markup libraries are popular amongst php devs?

good/popular ORMs?

what xml/html parsing library should I use?

is there a heroku equivalent?

Any info appreciated - remember I'm not asking if equivalents or php facilities for these exist at all, but what ones are popular (or rather, active, and used by good developers).

Cheers.

55 comments · 87% upvoted · other discussions

comments

mattindustries

PHP Farm might be what you are looking for to replace RVM

If there is something like bundler that would be pretty awesome. I would like to know about it.

For heroku, you could just use heroku

I can't really comment on the rest as the work I do mostly doesn't need any outside libraries and I sorta just write my own templating code which tends to be similar to smarty on implementation.

Sublime is a great editor, but many have been using phpstorm recently. Good luck, and really the php docs online are amazing if you ever need help.

ariah

PHP really does not require a lot of the tools that Ruby has in terms of rvm and rake. For gems, PHP can do most of its stuff either built in or simply by including other classes, but you can download/install some PEAR and PECL classes to do certain things if you want. I guess you want to use an ORM, but I just want to note that you don't have to..

PHP has an excellent built-in xml/html parser called DOMDocument (also SimpleXML, but it is more difficult to append/remove with that), and there is phpQuery (not built in).

I honestly don't really know what Heroku does in spite of checking it out. It just seems like a cloud platform. PHP is ridiculously easy to install compared to Rails.. you can get a full fledged PHP application with a framework to run on tiny hardware with no extensions. I am hosting three websites (one using Kohana, a framework) with 150MB of space on a shared hosting server.

I have to assume by ruby you mean rails. PHP is not a framework, and if you are not going to be using a framework such as Symfony or Kohana, you will have to start from scratch.

spidermonk [OP]

Right. I think this is sort of a cultural difference between the two languages? I mean, you can do all of that stuff without non std-lib libraries or tools in ruby too. And in my experience (non-trivial) deployment (on non-shared hosting) is roughly equivalent in difficulty these days. Just ruby seems to have a culture of reusing things and everyone seems more interested in gathering around a standard workflow more. There'll be some interesting sociological reason. Probably the dominance of rails, which pushes a "do things one way / reuse everything" philosophy.

I have to assume by ruby you mean rails.

Not at all. I mainly use Sinatra for web stuff (I think slim is the php equivalent). And I find myself doing a lot of stuff that is reasonably heavy non-framework code, but maybe has a web interface tacked on so others can use it easily, so I'm not thinking from just a "how to make a CRUD app as quickly as possible" perspective here.

[deleted]

[deleted]

evopix

Nor is there anything like Heroku for PHP (that I know of), and for the most part, it isn't needed.

There are actually quite a few Heroku style platforms for PHP, PHP Fog, Pagoda Box, cloudControl, Orchestra, and PHP Cloud just to name a few.

I would personally recommend Pagoda Box but that's just my personal preference.

ariah

I guessed wrong!

I've only used Ruby on Rails (but only on my own machine) and PHP. I think you may be right about the cultural thing -- I mean it's pretty easy to see a sort of "ruby culture.." just look at Github. I don't see that sort of thing with PHP.

ballscockr

Testing Libraries: If you are in to BDD then you can't go past Behat (http://behat.org) Good orm: propel or doctrine 2 heroku equivalent: no real need. any shared host with ssh (for baby projects anyway) bunder: symfony2 uses things called bundles.

rpnzl

Check out or orchestra.io for something heroku-like.

baileylo

Community feel free to tell me when you disagree.

  • rvm - No
  • bundler - Unsure - I feel like this is built into Compsore
  • rake - No
  • rubygems - I'd say use only pear2.php.net packages not pear.php.net packages. I haven't used composer but a lot of people certainly seem to love it. I tend to check github if I don't know of an existing package to do something.
  • testing - phpunit
  • Markup - Savant, Smarty, Twig
  • ORM - Doctrine or Propel
  • xml - Simple Xml
  • HTML - Dom

Somethings You're Missing

If you're planning to use Symfony, use twig as your markup language.

bd808
[deleted]

You can still use rake for common tasks in a PHP application, ie: building sass and coffee script, running migrations, installing git hooks, etc ... Sometimes it's just easier.

For example, at work we have a dev environment in a vagrant box. We can easily run commands on this using the vagrant gem like so:

vagrant_env.primary_vm.channel.sudo(cmd)

I haven't looked into how you would do it in PHP, but you have pick the right tool for the right job.

Gnascher

Rake is a Rails concept. CakePHP has a similar construct called (oddly enough) cake... It's a little like you crammed the rails command and the rake command together. It is used to build a new project, scaffolding, models, etc... so like rails g model [ModelName], as well as to manipulate stuff within the project like rake db:migrate ... except Cake doesn't have migrations (or at least didn't last time I used it).

While PEAR is similar to rubygems ... don't forget about PECL too.

spidermonk [OP]

You can find rake lots of places outside rails these days though. I don't use rails, but I use rake where-ever possible for running tests and such. Just for convenience and familiarity.

WyriHaximus

There is a cake plugin for that from the company behind CakePHP: https://github.com/CakeDC/migrations

Gnascher

Good to know. Since Cake is basically modeled off of rails, this is really part of the natural evolution.

spidermonk [OP]

Thanks.

[deleted]

rake (do people just use make?)

I've yet to ever hear of PHP devs that need a make process. I can't imagine what you would use it for...

rubygems (should I be using php-pear or composer? something else?)

Composer. PEAR is dying.

what testing libraries to use? (simpletest?)

PHPUnit is the gold standard

good/popular templating/markup libraries are popular amongst php devs?

PHP is a templating language all on its own, but if you absolutely feel compelled to use one on top of it, the most popular options are Smarty and Twig.

good/popular ORMs?

Doctrine.

what xml/html parsing library should I use?

PHP has a built in xml parser that's already pretty awesome.

is there a heroku equivalent?

There are more cloud based PHP hosting services than there are actual clouds in the sky. PHPFog is a decent starting point, their free plan will give you a place to put up simple applications. It's also fairly easy to get a LAMP stack running on a free Amazon EC2 instance.

spidermonk [OP]

Thanks - useful answers.

In case you're interested, people tend to use rake to run tasks like tests and database setup, that sort of thing. So you install someone else's application and type:

$ rake

and it will run its unit tests, check your config file for database settings and create tables and such... that sort of stuff. It's a nice way to make fiddly tasks easy. In rails to apply database changes to your production db you'd type:

RAILS_ENV=production rake db:migrate

It's not essential, but it's a sort of informal standard way of having other devs interact with your apps.

[deleted]

Ah, ok, unit testing makes sense.

Fustrate

ORMs:

Templates:

  • Twig
  • Smarty (warning: people will hate you for it)

People will argue that PHP is already a template engine, but I tend to disagree. This article sums it up nicely.

PHP includes an XML parsing library called SimpleXML. IIRC Symfony also includes an XML parser, I know there's a YAML one so I'd assume there's an XML one.

Testing: PHPUnit

Pornhub_dev

People will argue that PHP is already a template engine, but I tend to disagree. [5] This article sums it up nicely.

This article is also wrong on a lot of points (and the fact that I don't like F.Potencier to begin with has nothing to do with it :D) :

  • I don't know where he got his "stats", but from what I've seen in every company I've worked in -and a lot of others-, templates are not edited by designers, but by developers, usually front-end developers that have programming knowledge.
  • The short syntax for <?php echo is valid and should be used. The fact that he doesn't even explain his point of view just makes me want to dismiss the rest of the article.

  • The template oriented syntax is just a matter of taste, I find the Django syntax to be horrible to read. This should not even be in the article.

  • He completely discredit himself when saying PHP used to be a templating engine, and is not anymore. All the feature that made PHP a templating language are still present.

Also, and this is my opinion, templating engine just get in the way, they add a useless layer of complexity while obfuscating the templating logic. I'm a PHP developer, if I open a template I want to be able to make a change in a snap.

My experience with templating engine has always been the following: need to do a change, open template, look for what I want to modify, WTF myself as the code makes no sense, read through pages of documentation to understand how this bullshit of templating engine does simple operation such as If or loops, pull my hair for 30min, do the change. If the template is written in PHP, I open it, do my change, move on, 5min tops, and I'm not frustrated when I'm done with it.

Templating engines are a plague to PHP, they might be useful in very specific cases, but in a standard team, no they are not, if you have a designer doing your templates, then you can only blame yourself for not staffing your team properly, you would have to go over my dead body for me to let a designer touch or change the code.

Imortallus

Good writeup + are you really a pornhub dev?

Pornhub_dev

Was for 4 years, not anymore.

Imortallus

Respect.

krues8dr

Yeah, just use Symfony and you get all of those and a nice MVC that is pretty easy coming from Rails. No sense in using those piecemeal, really.

xangelo

What do you think of an ORM like RedBeanPHP?

ariah

I would suggest PHPTAL as a template engine. Or you can use good ol' XSLT, but I really love PHPTAL a lot.

Fustrate

Personally, I'm not a fan of anything that's XML-based. Just too verbose for me, and I think it's too hard to read quickly. Does PHPTAL work when you're not outputting HTML?

ariah

I personally hate anything that's bracket-based .. potato potahto, I just want him to know options available. You can output anything you want with PHPTAL including json and plaintext .. probably not the best tool to do so, but you could.

novelty_string

PHPTAL sucks some serious balls.

ariah

Statements like these are harmful to the development community. You are entitled to your opinion. why does it suck some serious balls?

novelty_string

It starts with the ridiculous idea of placing everything into a valid xml document, and finishes by making these attribute strings executable PHP that doesn't actually behave like PHP.

Sorry, but everything about it just plain sucks. Perhaps you can back up your recommendation or I would put it to you that you are doing far more damage than me by pointing people at something so poor.

ariah

I wouldn't recommend using php: -- I don't understand why the idea of creating a valid xml document for a template is "ridiculous," though.

novelty_string

Well for one, it's incredibly hard to read and extremely error prone. Particularly when you (as most will be) are working with html anyway.

I mean, perhaps xml as a template can work, but what we're doing here is taking an html document, forcing it to be xml, and then littering it with what at a glance looks like html (specially to your highlighter) but is actually special instructions with no demarcation of variables/functions/conditions.

ariah

I wouldn't consider twig to be like something any user would have experienced .. it has to be learned just the same. I don't think of xml as hard to read or error prone (especially extremely so) .. since PHPTAL parses the DOM tree beforehand, you can find any errors in the xml and correct them pretty easily. I agree with what you said..you're going to be working with html anyway, so why not use html as the template?

novelty_string

Sorry, my bad, I edited before I noticed your reply and now have no clue what was there.

As an example of twig/etc being easier to adjust to:

{% for user in users %}
    * {{ user.name }}
{% else %}
    No user have been found.
{% endfor %}

This is just like php, however <tal:block repeat="foo bar">/tal:block isn't. Sure that's a pretty easy one to follow, hopefully it illustrates.

[deleted]
ariah

I guess it does but I don't see how the PHPTAL is not hard to follow -- it's a slightly different syntax, but that's a pretty easy one to learn. The above is not like PHP syntax. Granted, there are some similarities .. I admit that the TAL "datum data" is weird and should probably be reversed, but this is a product of Zope TAL rather than PHPTAL itself.

I'm also not sure how twig works really / I've never used it, but in PHPTAL you can put the repeat on another element so it does not have to be wrapped.

sli

And there's the added benefit of picking up Jinja skills from Twig.

novelty_string

Well I prefer to just use html with minimal php.

jimdoescode

Welcome aboard.

My only suggestions are to not try to compare PHP to Ruby. They are different beasts and doing that will only frustrate you. Also try to learn the language a bit prior to jumping into a framework. Given your background you should be able to pick it up pretty quickly.

Most of the constructs you mentioned are framework dependent. There are some stand alone options but you will probably want something more framework centric. When you do take the plunge into a framework just do some homework and you should find equivalents to what you are used to.

Just about any of the frameworks you hear people talking about in here are good frameworks with solid active communities of quality devs, so just take your pick.

FamilyHeirloomTomato

Don't touch PEAR with a 10 foot pole. It is nasty. It has bad documentation, and each package is maintained independently, so some stuff is good and others suck. I had to work with the database package (MDB2 ?) at work and wanted to shoot my face off.

[deleted]

The biggest downside to PHP is how fragmented the community is. There are likely solutions to everything on your list. But a few of them are going to be difficult to find and none of them are used by the entire community. This is one of the driving reasons I'm looking to migrate to Ruby for web development. The community really has rallied around Rails and it has been great for creating a more streamlined development process.

ensiferous

I see some people say that you don't need a build process for PHP. Ignore those.

rake -> pake

Alternatively, you could go phing, but pake is just too simple and awesome to bother with anything more complicated.

htpasswd

Stay in Ruby for your own sake, PHP is severely flawed. As a PHP dev myself (whos trying to migrate to Py) i suggest you read this article. Anything in there is true, and in most of the cases, irrefutable.

[deleted]

He specifically said he's learning it for "work-related reasons", that makes it pretty clear that he doesn't have a choice in the matter.

Also, a LOT of that article is incorrect.

htpasswd

Yes, there are a few things on that comment which are correct. However, if you read the comment, you can see hes trying to justify the way PHP does it, much like the author's analogy says: You pull out the hammer, but to your dismay, it has the claw part on both sides. Still serviceable though, I mean, you can hit nails with the middle of the head holding it sideways.

spidermonk [OP]

Yip I've read it. I'm a little terrified. But php is hugely dominant where I am, and if I want to level up professionally I should know some. I'm not giving up on ruby, I just also want to be confident diving under the hood of the various hugely popular CMS packages used where I am.

And my previous experience tells me that will be less painful if I get a general foundation making things myself in the language before hand.