SlideShare a Scribd company logo
PHP Doesn't Suck
Who are you?


                     John Hobbs

                     - Developer at What Cheer
                     - @jmhobbs
                     - https://github.com/jmhobbs
                     - http://velvetcache.org/




PHP Doesn't Suck
PHP Sucks

                   T_PAAMAYIM_NEKUDOTAYIM

                     get_class() => gettype()

       PHPE9568F34-D428-11d2-A769-00AA001ACF42

                         sort( &$array )


                        www.phpsadness.com
PHP Doesn't Suck
PHP Sucks

                                             Low Barrier To Entry
                                              Weak Community
                                              Google-Copy-Paste
                                                    NIH

      “In the end I think you will find that your homegrown
      small framework has saved you time and aggravation
      and you end up with a better product.” - Rasmus

             http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html

PHP Doesn't Suck
I can write
                   terrible code in
                    any language.
                                - Me

PHP Doesn't Suck
Making It Not Suck

                   Learn the Language




                    http://php.net/manual


PHP Doesn't Suck
Making It Not Suck

                        Test Your Code




                      http://www.simpletest.org/
                        http://www.phpunit.de/
                   http://qa.php.net/write-test.php


PHP Doesn't Suck
Making It Not Suck

                       NO LIVE EDITS
                             (mostly)




               CAPISTRANO WORKS FINE WITH PHP

PHP Doesn't Suck
Making It Not Suck
                      Share & Be shared




                                  Github
                   PSR-0 (http://tinyurl.com/yh6jydd)

PHP Doesn't Suck
Making It Not Suck
                         Have A Style




        http://www.mediawiki.org/wiki/Manual:Coding_conventions

PHP Doesn't Suck
Making It Not Suck
                          Try The REPL
          jmhobbs@Cordelia:~$ phpsh
          Starting php
          type 'h' or 'help' to see instructions & features
          php> echo "Oh hai!";
          Oh hai!
          php> include "test.php";

          php> whoa();
          lol, functions!1!
          php>
          jmhobbs@Cordelia:~$


                       http://www.phpsh.org/

PHP Doesn't Suck
Making It Not Suck
                         Read Code
                      (Including other languages!)




PHP Doesn't Suck
USE
        A
   FRAMEWORK
                   (Hint: Not Zend)
PHP Doesn't Suck
Use A Framework


                    - HMVC
                    - Useful helpers
                    - Super flexible
                    - Great modules system
                    - Great modules


                    http://kohanaframework.org/
PHP Doesn't Suck
Use A Framework



         namespace appcontrollers;

         class PostsController extends lithiumactionController {

              public function index() {
                  return array('foo' => 'bar', 'title' => 'Posts');
              }
         }



                                 http://lithify.me/
PHP Doesn't Suck
Use A Framework
                                    Skunk
         // Initialize
         $s = new Skunk();

         // Add a route
         $s->get(
            '/hi(/<name>)',
            function ( &$s, $name = “world” ) {
              $s->body = “Hello $name!";
            }
         );

         // Run it!
         $s->run();


                        https://github.com/jmhobbs/Skunk
PHP Doesn't Suck
So...
PHP Doesn't Suck
It's Getting Better
    5.4

      - http://www.php.net/manual/en/language.oop5.traits.php
        (Traits => Mixins)

      - http://svn.php.net/viewvc?view=revision&revision=313641
        (Short Array Syntax: [ “a” => “b” ])

      - http://news.php.net/php.internals/55293
        (SVN => git)



PHP Doesn't Suck
Discussion


                   Questions?
                   Comments?

PHP Doesn't Suck
PHP Doesn't Suck




This is a presentation about PHP.

If you are looking for a fight, leave now.
Who are you?


                           John Hobbs

                           - Developer at What Cheer
                           - @jmhobbs
                           - https://github.com/jmhobbs
                           - http://velvetcache.org/




      PHP Doesn't Suck



I'm John Hobbs.

I make fancy websites at What Cheer.

I have a twitter and a github and I blog but no one
   reads it.

If I'm known for anything on the Internet it's Beef Taco.

Just google Beef Taco and it's the top item.

I kid you not.
PHP Sucks

                        T_PAAMAYIM_NEKUDOTAYIM

                          get_class() => gettype()

            PHPE9568F34-D428-11d2-A769-00AA001ACF42

                              sort( &$array )


                             www.phpsadness.com
     PHP Doesn't Suck



PHP Sucks.

The language itself has some fundamental flaws that
 crept in early in it's life and have not been excised
 yet, mostly for compatibility issues.

Crappy error messages.
Inconsistent naming conventions.
Stupid “features”
In place array sorts.

There is a decent chunk of these, phpsadness.com is
 a good place to read and track them.

PHP has a weird history of full rewrites, but it's held
 onto backwards compatibility through a lot of them.

Zend (4/5) is a decent engine, but the old cruft is lame.
PHP Sucks

                                                   Low Barrier To Entry
                                                    Weak Community
                                                    Google-Copy-Paste
                                                          NIH

            “In the end I think you will find that your homegrown
            small framework has saved you time and aggravation
            and you end up with a better product.” - Rasmus

                   http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html

      PHP Doesn't Suck



Why else does PHP suck?

Well, it runs everywhere. It's billed as an easy
 language to learn, fast. And it is, if you want to write
 crappy code.

The community is, compared to Python and Ruby,
 fragmented and not sophisticated. Testing is a big
 problem here. Ever used a phpt?

Because PHP is everywhere, you can Google for
 anything and get some code. Too often people don't
 read it, they just copy-paste. So they lose a chance
 to learn and also integrate crappy code.

There also seems to be a serious not-invented-here
 syndrome in PHP. This includes Rasmus. Don't
 listen to Rasmus.
I can write
                         terrible code in
                          any language.
                                       - Me

      PHP Doesn't Suck



I can write terrible code in any language.

The point is that the quality of the code has a lot to do
 with who is writing it, and how much they
 understand.

Don't blame everything on the language.

So how can we write better PHP?
Making It Not Suck

                         Learn the Language




                          http://php.net/manual


      PHP Doesn't Suck



Learn the language.

It sounds simple, but I bet there is lots of stuff that even
   good PHP programmers don't know about PHP.

Has anyone here ever written a __clone method?

How much of the manual have you read?

Have you ever compiled an extension? Written one?
Making It Not Suck

                             Test Your Code




                           http://www.simpletest.org/
                             http://www.phpunit.de/
                        http://qa.php.net/write-test.php


     PHP Doesn't Suck



Test your code.

This is a huuuuge deal. There are good testing tools
 for PHP, use them. I like SimpleTest, but it's a
 personal choice, and an easy one.

TDD makes you think, something PHP doesn't always
 make you do.

Something else that unit testing does is force you to
 separate code. PHP is it's own template language,
 so it's super easy to mix business logic with
 presentation. Don't. Testing will help.
Making It Not Suck

                                 NO LIVE EDITS
                                       (mostly)




                         CAPISTRANO WORKS FINE WITH PHP

      PHP Doesn't Suck



No live edits. Stay off of production.

I admit, I don't use version control on some stuff. One
   off tools and pages, wordpress blogs, stuff that
   doesn't really matter.

If you are writing an app or a library, you should be
   using version control and running deployments after
   all your tests pass.

Capistrano gets along fine with PHP, and if you would
 rather you can use phing and other tools.

PHP tempts you to edit live in production. Resist.
Making It Not Suck
                            Share & Be shared




                                        Github
                         PSR-0 (http://tinyurl.com/yh6jydd)

      PHP Doesn't Suck



Share your code, and use shared code.

You don't have to come up with your own version of a
 lot of things.

But don't just blindly copy code or use any old module.

Look at the code and make a judgment call. It's okay
  to fork or rewrite if it's in bad shape, but then share it
  back to the community!

If you are writing a library, be compatible. If it's
   generic, there are naming conventions like PSR-0.

(I admit I am bad at being compatible)
Making It Not Suck
                               Have A Style




              http://www.mediawiki.org/wiki/Manual:Coding_conventions

      PHP Doesn't Suck



Have a style you stick to.

Being clear and consistent in your code is essential, no
 sloppy formatting.

Bad style is endemic of google-copy-paste code.

If you are working on someone else's project, use their
    style before you make a pull request.

It's polite, it's clean it's essential.

I use a variant of MediaWiki's conventions.
Making It Not Suck
                                Try The REPL
                jmhobbs@Cordelia:~$ phpsh
                Starting php
                type 'h' or 'help' to see instructions & features
                php> echo "Oh hai!";
                Oh hai!
                php> include "test.php";

                php> whoa();
                lol, functions!1!
                php>
                jmhobbs@Cordelia:~$


                             http://www.phpsh.org/

      PHP Doesn't Suck



Other languages have a great REPL.

PHP, not so much.

Luckily we have a good one from Facebook, written
  mostly in Python actually.

Get it and give it a shot.

When you forget argument ordering it's often easier to
 try it in the shell than to go look it up on php.net.
Making It Not Suck
                              Read Code
                           (Including other languages!)




     PHP Doesn't Suck



Actually READ the code you use.

This one is a big one. Read other people's code, the
 good and the bad.

Identify what you like and what you don't like about
  other people's code.

Try out new things you find in other peoples code.

And don't be just a PHP programmer.

Read and write some other languages, Python, Ruby,
 whatever.

I am convinced the more well read you are, in any
   language, the better you will be as a programmer.
USE
             A
        FRAMEWORK
                        (Hint: Not Zend)
     PHP Doesn't Suck



Use a framework.

A framework will make you organize your code within a
  set of conventions. Which conventions don't matter
  as much as the fact that they exist.

I recommend not Zend because it frightens me.

Learn your framework well.

Read it's core, submit patches, be involved.

Here are few examples of frameworks:
Use A Framework


                          - HMVC
                          - Useful helpers
                          - Super flexible
                          - Great modules system
                          - Great modules


                          http://kohanaframework.org/
      PHP Doesn't Suck



I'm a Kohana user.

It's not all roses though, there are no migrations either,
   which is gross.

Development moves fast, and breaks api a lot. It's
 managed with versioning though, and there is plenty
 of backporting and bug fixes.
Use A Framework



              namespace appcontrollers;

              class PostsController extends lithiumactionController {

                   public function index() {
                       return array('foo' => 'bar', 'title' => 'Posts');
                   }
              }



                                      http://lithify.me/
     PHP Doesn't Suck



Another cool one is Lithium.

It's very “leading edge” and uses namespaces like they
   are going out of style.
Use A Framework
                                         Skunk
              // Initialize
              $s = new Skunk();

              // Add a route
              $s->get(
                 '/hi(/<name>)',
                 function ( &$s, $name = “world” ) {
                   $s->body = “Hello $name!";
                 }
              );

              // Run it!
              $s->run();


                             https://github.com/jmhobbs/Skunk
     PHP Doesn't Suck



Finally I included a Sinatra and Bottle style framework
  that I wrote.

I wouldn't necessarily recommend using Skunk, but it's
  a good example a little, single file framework with an
  interesting API and feel.
So...
      PHP Doesn't Suck



So.

Those are my thoughts on how to write better PHP.

As for the language itself...
It's Getting Better
          5.4

            - http://www.php.net/manual/en/language.oop5.traits.php
              (Traits => Mixins)

            - http://svn.php.net/viewvc?view=revision&revision=313641
              (Short Array Syntax: [ “a” => “b” ])

            - http://news.php.net/php.internals/55293
              (SVN => git)



      PHP Doesn't Suck



It's getting better.

5.4 is on it's way and it's bringing some fixes for major
  pain points.
Discussion


                        Questions?
                        Comments?

     PHP Doesn't Suck



Please be gentle.

More Related Content

What's hot (20)

PPT
Chicken
guestf65951a
 
PDF
Präsentationstraining PowerPoint Karaoke
mspgermany
 
PDF
Seattle Creative Mornings: Battledecks!
Luz Bratcher
 
PPT
PowerPoint Karaoke Slides - The Internet
pampf
 
PPT
PowerPoint Karaoke (Sample Presentation)
Amber Case
 
PPTX
The battle for attention
Newsworks
 
PDF
How Python Programmers Can Change the World
Joshua Tauberer
 
PPTX
Power Point Karaoke for 6
Amber Case
 
PPTX
Battledecks Il09
Janie Hermann
 
PPT
Power Point Karaoke Slides - Love Relationships
pampf
 
PDF
Powerpoint Karaoke - ISTE Session
Jon Corippo
 
PPTX
Powerpoint Karaoke, Maputo 2015
Suranga Nath Kasthurirathne
 
PPTX
PowerPoint Karaoke
Dave Manningsmith
 
PDF
Boring to Bold: Presentation Design Ideas for Non-Designers
Michael Gowin
 
PDF
Clickbait: A Guide To Writing Un-Ignorable Headlines
Venngage
 
PDF
Open Government Is Like Poetry
Joshua Tauberer
 
PDF
Designing Presentations
The Media Kitchen
 
PDF
Powerpoint-Karaoke (Erläuterungen)
Anja Lorenz
 
PDF
4 Biggest Challenges for Creative Teams
Wrike
 
PDF
People Don't Care About Your Brand
Slides That Rock
 
Chicken
guestf65951a
 
Präsentationstraining PowerPoint Karaoke
mspgermany
 
Seattle Creative Mornings: Battledecks!
Luz Bratcher
 
PowerPoint Karaoke Slides - The Internet
pampf
 
PowerPoint Karaoke (Sample Presentation)
Amber Case
 
The battle for attention
Newsworks
 
How Python Programmers Can Change the World
Joshua Tauberer
 
Power Point Karaoke for 6
Amber Case
 
Battledecks Il09
Janie Hermann
 
Power Point Karaoke Slides - Love Relationships
pampf
 
Powerpoint Karaoke - ISTE Session
Jon Corippo
 
Powerpoint Karaoke, Maputo 2015
Suranga Nath Kasthurirathne
 
PowerPoint Karaoke
Dave Manningsmith
 
Boring to Bold: Presentation Design Ideas for Non-Designers
Michael Gowin
 
Clickbait: A Guide To Writing Un-Ignorable Headlines
Venngage
 
Open Government Is Like Poetry
Joshua Tauberer
 
Designing Presentations
The Media Kitchen
 
Powerpoint-Karaoke (Erläuterungen)
Anja Lorenz
 
4 Biggest Challenges for Creative Teams
Wrike
 
People Don't Care About Your Brand
Slides That Rock
 

Viewers also liked (20)

PDF
Unit testing in PHP
Lee Boynton
 
PPTX
Random powerpoint
IlluimnatiIsGr8
 
PPT
Erin elchesyn the digestive system
Mrs Seo
 
PPT
Wwe john cena
Tharun Sivakumar
 
PPT
Essentials of corr med presentation -understanding the legal enviroment in co...
Zoey Lovell
 
PPT
Jack murrell wright digestive system
Mrs Seo
 
PDF
SharingEconomy: The Buzzword of the Moment
Simone Cicero
 
PPT
The secret order of the illuminati
Riaz Zalil
 
PPTX
ppt on Industrial policy
Codelaxy Ltd.
 
PPT
A Generic Apple "Steve Jobs" style Keynote Address Presentation
The App Store Chronicle
 
PPTX
Illuminati presentation
04burkem
 
PDF
Buzzword Bingo 2017
ron mader
 
PPTX
How to think like a startup v3
Loic Le Meur
 
PPTX
Industrial policy.ppt
Shikha Gupta
 
PPTX
Steve Jobs Inspirational Quotes
InsideView
 
PDF
The Build Trap
Melissa Perri
 
PPTX
Shall we play a game?
Maciej Lasyk
 
PDF
The Future of Everything
Charbel Zeaiter
 
PDF
Hype vs. Reality: The AI Explainer
Luminary Labs
 
PDF
Designing Teams for Emerging Challenges
Aaron Irizarry
 
Unit testing in PHP
Lee Boynton
 
Random powerpoint
IlluimnatiIsGr8
 
Erin elchesyn the digestive system
Mrs Seo
 
Wwe john cena
Tharun Sivakumar
 
Essentials of corr med presentation -understanding the legal enviroment in co...
Zoey Lovell
 
Jack murrell wright digestive system
Mrs Seo
 
SharingEconomy: The Buzzword of the Moment
Simone Cicero
 
The secret order of the illuminati
Riaz Zalil
 
ppt on Industrial policy
Codelaxy Ltd.
 
A Generic Apple "Steve Jobs" style Keynote Address Presentation
The App Store Chronicle
 
Illuminati presentation
04burkem
 
Buzzword Bingo 2017
ron mader
 
How to think like a startup v3
Loic Le Meur
 
Industrial policy.ppt
Shikha Gupta
 
Steve Jobs Inspirational Quotes
InsideView
 
The Build Trap
Melissa Perri
 
Shall we play a game?
Maciej Lasyk
 
The Future of Everything
Charbel Zeaiter
 
Hype vs. Reality: The AI Explainer
Luminary Labs
 
Designing Teams for Emerging Challenges
Aaron Irizarry
 
Ad

Similar to PHP Doesn't Suck (20)

PDF
PHP Web Development.pdf
Sonia Simi
 
PDF
Summer training report priyanka
priyanka kumari
 
PDF
Beginning PHP
Mohammed Safwat
 
PDF
Best Practices with Zend Framework - Matthew Weier O'Phinney
dpc
 
PDF
Migrating from PHP4 To PHP5 - Zend Webinar
Ivo Jansch
 
PDF
basic concept of php(Gunikhan sonowal)
Guni Sonow
 
PDF
More about PHP
Jonathan Francis Roscoe
 
PDF
Introduction to PHP (SDPHP)
Eric Johnson
 
PPT
Introduction to PHP - SDPHP
Eric Johnson
 
PDF
Rasmus, Think Again! Agile Framework == Happy Php Developer
Arno Schneider
 
PPTX
Php is best programming language converted
https://cilected.com/
 
PPT
phpwebdev.ppt
rawaccess
 
PDF
Professional PHP: an open-source alternative for enterprise development [Kort...
Combell NV
 
PDF
Tips
mclee
 
KEY
Fall 2011 PHP Class - Session 1
jimbojsb
 
PPT
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
DOCX
PHP Training In Chandigar1.docx
Excellence Academy
 
PPT
php introduction to the basic student web
ZahraWaheed9
 
PPTX
2016 03 15_biological_databases_part4
Prof. Wim Van Criekinge
 
PHP Web Development.pdf
Sonia Simi
 
Summer training report priyanka
priyanka kumari
 
Beginning PHP
Mohammed Safwat
 
Best Practices with Zend Framework - Matthew Weier O'Phinney
dpc
 
Migrating from PHP4 To PHP5 - Zend Webinar
Ivo Jansch
 
basic concept of php(Gunikhan sonowal)
Guni Sonow
 
More about PHP
Jonathan Francis Roscoe
 
Introduction to PHP (SDPHP)
Eric Johnson
 
Introduction to PHP - SDPHP
Eric Johnson
 
Rasmus, Think Again! Agile Framework == Happy Php Developer
Arno Schneider
 
phpwebdev.ppt
rawaccess
 
Professional PHP: an open-source alternative for enterprise development [Kort...
Combell NV
 
Tips
mclee
 
Fall 2011 PHP Class - Session 1
jimbojsb
 
PHP - Introduction to PHP Fundamentals
Vibrant Technologies & Computers
 
PHP Training In Chandigar1.docx
Excellence Academy
 
php introduction to the basic student web
ZahraWaheed9
 
2016 03 15_biological_databases_part4
Prof. Wim Van Criekinge
 
Ad

Recently uploaded (20)

PDF
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PPTX
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PPTX
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
PDF
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PPTX
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
PDF
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PPTX
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
PDF
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
PDF
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
PDF
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
PDF
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
PDF
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 
Agentic AI lifecycle for Enterprise Hyper-Automation
Debmalya Biswas
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
COMPARISON OF RASTER ANALYSIS TOOLS OF QGIS AND ARCGIS
Sharanya Sarkar
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
Agentforce World Tour Toronto '25 - MCP with MuleSoft
Alexandra N. Martinez
 
AI Agents in the Cloud: The Rise of Agentic Cloud Architecture
Lilly Gracia
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Future Tech Innovations 2025 – A TechLists Insight
TechLists
 
Newgen 2022-Forrester Newgen TEI_13 05 2022-The-Total-Economic-Impact-Newgen-...
darshakparmar
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Agentforce World Tour Toronto '25 - Supercharge MuleSoft Development with Mod...
Alexandra N. Martinez
 
[Newgen] NewgenONE Marvin Brochure 1.pdf
darshakparmar
 
“Squinting Vision Pipelines: Detecting and Correcting Errors in Vision Models...
Edge AI and Vision Alliance
 
LOOPS in C Programming Language - Technology
RishabhDwivedi43
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
NASA A Researcher’s Guide to International Space Station : Physical Sciences ...
Dr. PANKAJ DHUSSA
 
Newgen Beyond Frankenstein_Build vs Buy_Digital_version.pdf
darshakparmar
 

PHP Doesn't Suck

  • 2. Who are you? John Hobbs - Developer at What Cheer - @jmhobbs - https://github.com/jmhobbs - http://velvetcache.org/ PHP Doesn't Suck
  • 3. PHP Sucks T_PAAMAYIM_NEKUDOTAYIM get_class() => gettype() PHPE9568F34-D428-11d2-A769-00AA001ACF42 sort( &$array ) www.phpsadness.com PHP Doesn't Suck
  • 4. PHP Sucks Low Barrier To Entry Weak Community Google-Copy-Paste NIH “In the end I think you will find that your homegrown small framework has saved you time and aggravation and you end up with a better product.” - Rasmus http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html PHP Doesn't Suck
  • 5. I can write terrible code in any language. - Me PHP Doesn't Suck
  • 6. Making It Not Suck Learn the Language http://php.net/manual PHP Doesn't Suck
  • 7. Making It Not Suck Test Your Code http://www.simpletest.org/ http://www.phpunit.de/ http://qa.php.net/write-test.php PHP Doesn't Suck
  • 8. Making It Not Suck NO LIVE EDITS (mostly) CAPISTRANO WORKS FINE WITH PHP PHP Doesn't Suck
  • 9. Making It Not Suck Share & Be shared Github PSR-0 (http://tinyurl.com/yh6jydd) PHP Doesn't Suck
  • 10. Making It Not Suck Have A Style http://www.mediawiki.org/wiki/Manual:Coding_conventions PHP Doesn't Suck
  • 11. Making It Not Suck Try The REPL jmhobbs@Cordelia:~$ phpsh Starting php type 'h' or 'help' to see instructions & features php> echo "Oh hai!"; Oh hai! php> include "test.php"; php> whoa(); lol, functions!1! php> jmhobbs@Cordelia:~$ http://www.phpsh.org/ PHP Doesn't Suck
  • 12. Making It Not Suck Read Code (Including other languages!) PHP Doesn't Suck
  • 13. USE A FRAMEWORK (Hint: Not Zend) PHP Doesn't Suck
  • 14. Use A Framework - HMVC - Useful helpers - Super flexible - Great modules system - Great modules http://kohanaframework.org/ PHP Doesn't Suck
  • 15. Use A Framework namespace appcontrollers; class PostsController extends lithiumactionController { public function index() { return array('foo' => 'bar', 'title' => 'Posts'); } } http://lithify.me/ PHP Doesn't Suck
  • 16. Use A Framework Skunk // Initialize $s = new Skunk(); // Add a route $s->get( '/hi(/<name>)', function ( &$s, $name = “world” ) { $s->body = “Hello $name!"; } ); // Run it! $s->run(); https://github.com/jmhobbs/Skunk PHP Doesn't Suck
  • 18. It's Getting Better 5.4 - http://www.php.net/manual/en/language.oop5.traits.php (Traits => Mixins) - http://svn.php.net/viewvc?view=revision&revision=313641 (Short Array Syntax: [ “a” => “b” ]) - http://news.php.net/php.internals/55293 (SVN => git) PHP Doesn't Suck
  • 19. Discussion Questions? Comments? PHP Doesn't Suck
  • 20. PHP Doesn't Suck This is a presentation about PHP. If you are looking for a fight, leave now.
  • 21. Who are you? John Hobbs - Developer at What Cheer - @jmhobbs - https://github.com/jmhobbs - http://velvetcache.org/ PHP Doesn't Suck I'm John Hobbs. I make fancy websites at What Cheer. I have a twitter and a github and I blog but no one reads it. If I'm known for anything on the Internet it's Beef Taco. Just google Beef Taco and it's the top item. I kid you not.
  • 22. PHP Sucks T_PAAMAYIM_NEKUDOTAYIM get_class() => gettype() PHPE9568F34-D428-11d2-A769-00AA001ACF42 sort( &$array ) www.phpsadness.com PHP Doesn't Suck PHP Sucks. The language itself has some fundamental flaws that crept in early in it's life and have not been excised yet, mostly for compatibility issues. Crappy error messages. Inconsistent naming conventions. Stupid “features” In place array sorts. There is a decent chunk of these, phpsadness.com is a good place to read and track them. PHP has a weird history of full rewrites, but it's held onto backwards compatibility through a lot of them. Zend (4/5) is a decent engine, but the old cruft is lame.
  • 23. PHP Sucks Low Barrier To Entry Weak Community Google-Copy-Paste NIH “In the end I think you will find that your homegrown small framework has saved you time and aggravation and you end up with a better product.” - Rasmus http://toys.lerdorf.com/archives/38-The-no-framework-PHP-MVC-framework.html PHP Doesn't Suck Why else does PHP suck? Well, it runs everywhere. It's billed as an easy language to learn, fast. And it is, if you want to write crappy code. The community is, compared to Python and Ruby, fragmented and not sophisticated. Testing is a big problem here. Ever used a phpt? Because PHP is everywhere, you can Google for anything and get some code. Too often people don't read it, they just copy-paste. So they lose a chance to learn and also integrate crappy code. There also seems to be a serious not-invented-here syndrome in PHP. This includes Rasmus. Don't listen to Rasmus.
  • 24. I can write terrible code in any language. - Me PHP Doesn't Suck I can write terrible code in any language. The point is that the quality of the code has a lot to do with who is writing it, and how much they understand. Don't blame everything on the language. So how can we write better PHP?
  • 25. Making It Not Suck Learn the Language http://php.net/manual PHP Doesn't Suck Learn the language. It sounds simple, but I bet there is lots of stuff that even good PHP programmers don't know about PHP. Has anyone here ever written a __clone method? How much of the manual have you read? Have you ever compiled an extension? Written one?
  • 26. Making It Not Suck Test Your Code http://www.simpletest.org/ http://www.phpunit.de/ http://qa.php.net/write-test.php PHP Doesn't Suck Test your code. This is a huuuuge deal. There are good testing tools for PHP, use them. I like SimpleTest, but it's a personal choice, and an easy one. TDD makes you think, something PHP doesn't always make you do. Something else that unit testing does is force you to separate code. PHP is it's own template language, so it's super easy to mix business logic with presentation. Don't. Testing will help.
  • 27. Making It Not Suck NO LIVE EDITS (mostly) CAPISTRANO WORKS FINE WITH PHP PHP Doesn't Suck No live edits. Stay off of production. I admit, I don't use version control on some stuff. One off tools and pages, wordpress blogs, stuff that doesn't really matter. If you are writing an app or a library, you should be using version control and running deployments after all your tests pass. Capistrano gets along fine with PHP, and if you would rather you can use phing and other tools. PHP tempts you to edit live in production. Resist.
  • 28. Making It Not Suck Share & Be shared Github PSR-0 (http://tinyurl.com/yh6jydd) PHP Doesn't Suck Share your code, and use shared code. You don't have to come up with your own version of a lot of things. But don't just blindly copy code or use any old module. Look at the code and make a judgment call. It's okay to fork or rewrite if it's in bad shape, but then share it back to the community! If you are writing a library, be compatible. If it's generic, there are naming conventions like PSR-0. (I admit I am bad at being compatible)
  • 29. Making It Not Suck Have A Style http://www.mediawiki.org/wiki/Manual:Coding_conventions PHP Doesn't Suck Have a style you stick to. Being clear and consistent in your code is essential, no sloppy formatting. Bad style is endemic of google-copy-paste code. If you are working on someone else's project, use their style before you make a pull request. It's polite, it's clean it's essential. I use a variant of MediaWiki's conventions.
  • 30. Making It Not Suck Try The REPL jmhobbs@Cordelia:~$ phpsh Starting php type 'h' or 'help' to see instructions & features php> echo "Oh hai!"; Oh hai! php> include "test.php"; php> whoa(); lol, functions!1! php> jmhobbs@Cordelia:~$ http://www.phpsh.org/ PHP Doesn't Suck Other languages have a great REPL. PHP, not so much. Luckily we have a good one from Facebook, written mostly in Python actually. Get it and give it a shot. When you forget argument ordering it's often easier to try it in the shell than to go look it up on php.net.
  • 31. Making It Not Suck Read Code (Including other languages!) PHP Doesn't Suck Actually READ the code you use. This one is a big one. Read other people's code, the good and the bad. Identify what you like and what you don't like about other people's code. Try out new things you find in other peoples code. And don't be just a PHP programmer. Read and write some other languages, Python, Ruby, whatever. I am convinced the more well read you are, in any language, the better you will be as a programmer.
  • 32. USE A FRAMEWORK (Hint: Not Zend) PHP Doesn't Suck Use a framework. A framework will make you organize your code within a set of conventions. Which conventions don't matter as much as the fact that they exist. I recommend not Zend because it frightens me. Learn your framework well. Read it's core, submit patches, be involved. Here are few examples of frameworks:
  • 33. Use A Framework - HMVC - Useful helpers - Super flexible - Great modules system - Great modules http://kohanaframework.org/ PHP Doesn't Suck I'm a Kohana user. It's not all roses though, there are no migrations either, which is gross. Development moves fast, and breaks api a lot. It's managed with versioning though, and there is plenty of backporting and bug fixes.
  • 34. Use A Framework namespace appcontrollers; class PostsController extends lithiumactionController { public function index() { return array('foo' => 'bar', 'title' => 'Posts'); } } http://lithify.me/ PHP Doesn't Suck Another cool one is Lithium. It's very “leading edge” and uses namespaces like they are going out of style.
  • 35. Use A Framework Skunk // Initialize $s = new Skunk(); // Add a route $s->get( '/hi(/<name>)', function ( &$s, $name = “world” ) { $s->body = “Hello $name!"; } ); // Run it! $s->run(); https://github.com/jmhobbs/Skunk PHP Doesn't Suck Finally I included a Sinatra and Bottle style framework that I wrote. I wouldn't necessarily recommend using Skunk, but it's a good example a little, single file framework with an interesting API and feel.
  • 36. So... PHP Doesn't Suck So. Those are my thoughts on how to write better PHP. As for the language itself...
  • 37. It's Getting Better 5.4 - http://www.php.net/manual/en/language.oop5.traits.php (Traits => Mixins) - http://svn.php.net/viewvc?view=revision&revision=313641 (Short Array Syntax: [ “a” => “b” ]) - http://news.php.net/php.internals/55293 (SVN => git) PHP Doesn't Suck It's getting better. 5.4 is on it's way and it's bringing some fixes for major pain points.
  • 38. Discussion Questions? Comments? PHP Doesn't Suck Please be gentle.