SlideShare a Scribd company logo
1 of 19
Download to read offline
P P os' uk
                   H D en Sc
                         t




This is a presentation about PHP.

If you are looking for a fight, leave now.
Wh ae o?
                     o r yu


                        Jh H b s
                        on ob

                        - ee p r t a C er
                        D vl e a Wh t he
                            o
                        - jhb s
                        @m o b
                        -ts /iu. m jhb s
                        hp: ghb o / o b
                          t/ t c m
                        -t: vl t ce r/
                        hp /e e ah. g
                          t/ v c    o




      P P os' uk
      H D en Sc
            t



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.
P P uk
                       H Scs

                  TP A Y N K D TYM
                  _A MA I E U O A I
                        M_

                   g t l s = g tp (
                    e c s ) > e ye)
                     _a (      t

         P P9 6 F4 4 8 1 2A 6 - A 0 1 C 4
         H E 5 83 - 2 - d -7 9 0 A 0 A F 2
                  D   1       0

                       sr & ary
                       ot $ r )
                         (   a


                     w wppa nscm
                      w . sd es o
                         h    .
     P P os' uk
     H D en Sc
           t



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.
P P uk
                          H Scs

                               LwB re T Et
                               o ar ro n y
                                     i    r
                                We k o m ny
                                 a C m ui t
                               G o lC p - s
                                o g -o y at
                                   e    P e
                                    NH
                                     I

         “ t edI i yu ifd h to r o erw
         I h n tn o wli t yu h m go n
          n e     hk     ln a
         s a f m w r h sae yuie n a gaai
         m lr e ok a svd o t a d g rvtn
            la               m         o
         a d o ed p i a ee po ut -am s
          n yu n u wt b tr rd c” R s u
                      h   t    .

             hp/t sed rcm aci s3 - e orm w r- P Cf m w r.m
             t: o .rofo /r v / 8 h- -a e ok H - -a e ok tl
              t / yl   .   he    T nf       P MV r      h

      P P os' uk
      H D en Sc
            t



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.
Ia w i
                     cn re
                         t
                   t r lcd i
                   e ie o en
                    rb
                   ayaga e
                    n l ug.
                       n
                                       -
                                       Me

      P P os' uk
      H D en Sc
            t



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?
Mai I oSc
                     k g t tuk
                      n N

                   Lan h Ln u g
                   e r te a g a e




                    hp /h . t a u l
                     t : p pn / na
                     t/     em


      P P os' uk
      H D en Sc
            t



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?
Mai I oSc
                    k g t tuk
                     n N

                     TsY u C d
                     et o r o e




                   h p/ww .m l et r/
                    t:
                     t / ws pe sog
                            i t .
                    ht: w .h u i e
                     t / wwp p n . /
                      p/         td
                  ht: q .h . t reet h
                   t / ap pn / i -sp p
                    p/      e w tt .


     P P os' uk
     H D en Sc
           t



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.
Mai I oSc
                     k g t tuk
                      n N

                     N L E DT
                      O I EI
                        V   S
                           ( ot )
                           m sy
                              l




               C P TA O WOR S I E T P P
                AI R N
                  S        K F WI H
                              N   H

      P P os' uk
      H D en Sc
            t



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.
Mai I oSc
                      k g t tuk
                       n N
                     S ae B sae
                      h r & e h rd




                            Gt b
                             iu
                              h
                    S - hp/ i ulo /h j )
                   P R0(t : t y rcm y 6y d
                         t /n .         d

      P P os' uk
      H D en Sc
            t



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)
Mai I oSc
                      k g t tuk
                       n N
                         H v ASy
                          a e tle




           hp / w .ei i. gwk Maul o i _ovnos
           t: w wm d wko / i/ naC d g cnetn
            t/      a ir    i   : n       i

      P P os' uk
      H D en Sc
            t



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.
Mai I oSc
                     k g t tuk
                      n N
                       T Te E L
                       r h RP
                        y
            jhbsCrei:$pph
             mob@odla~ hs
            Satn pp
             trig h
            tp ''o 'ep t seisrcin &faue
             ye h r hl' o e ntutos etrs
            pp eh "hhi"
             h> co O a!;
            O hi
             h a!
            pp icue"etpp;
             h> nld ts.h"

            pp wo(;
             h> ha)
            ll fntos1
             o, ucin!!
            pp
             h>
            jhbsCrei:$
             mob@odla~


                     ht: w .h s.r/
                      t / wwp ph g
                       p/       o

      P P os' uk
      H D en Sc
            t



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.
Mai I oSc
                    k g t tuk
                     n N
                        Ra C d
                         ed o e
                      ( c d goh ra g a e!
                      I l i te ln u g s
                       nu n             )




     P P os' uk
     H D en Sc
           t



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.
UE
           S
           A
       F A WOR
       R ME   K
                   (i: o Zn)
                   Hn N t ed
                     t
     P P os' uk
     H D en Sc
           t



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:
Ue F m w r
                    s A r e ok
                        a


                     - MV
                     H C
                     - sf hl r
                     Ue le es
                        u p
                     -u e fx l
                     Sp rl ie
                           eb
                     - ra m dl ss m
                     G e t o u syt
                              e  e
                     - ra m dl
                     G et o u s
                              e


                     hp /oaarm w r og
                      t: khnf e ok r/
                      t/     a    .
      P P os' uk
      H D en Sc
            t



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.
Ue F m w r
                    s A r e ok
                        a



          nmsaeapcnrles
           aepc potolr;
          casPssotolretnsihucinCnrle {
           ls otCnrle xed ltimatootolr
              pbi fnto idx){
               ulc ucin ne(
                 rtr ary'o'= 'a' 'il'= 'ot';
                  eun ra(fo > br, tte > Pss)
              }
          }



                        hp /tfm /
                         t: l i.e
                         t/ i y
                             h
     P P os' uk
     H D en Sc
           t



Another cool one is Lithium.

It's very “leading edge” and uses namespaces like they
   are going out of style.
Ue F m w r
                    s A r e ok
                        a
                         Suk
                          kn
          / Iiilz
           / ntaie
          $ =nwSuk)
          s   e kn(;

          / Adarue
           / d   ot
          $-gt
           s>e(
           'h(<ae),
             /i/nm>'
           fnto (&s $ae=“ol”){
             ucin   $, nm  wrd
              $-bd =“el $ae"
               s>oy  Hlo nm!;
           }
          );

          / Rni!
           / u t
          $-rn)
           s>u(;


                   hp: ghb o / hb sSuk
                    ts /iu. m j o b/kn
                    t/ t c m
     P P os' uk
     H D en Sc
           t



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.
S.
                    o.
                     .
      P P os' uk
      H D en Sc
            t



So.

Those are my thoughts on how to write better PHP.

As for the language itself...
I G t g ee
                       t ei B tr
                        ' t
                        s   n   t
         54
          .

         -t: w wpp e m na e/ n ug. p .as h
         hp / w . . t a ul nl ga e o 5t i. p
           t/     hn/    / a      o   r tp
          ( as > x s
          T i = Min)
           rt     i

         -t: s . p e v w cv w rvi &eio= 1 6 1
         hp /v p . t i v?i =eio rvi 33 4
           t/ n h n / e    e    sn  sn
          (hrAry yt : “” > b ]
          Sot r Sn x[a = “” )
               a    a

         -t: nw . p e ppn ra /5 9
         hp /e s h. t h.t nl 5 2 3
           t/   p n / ie s
          (V = g)
          SN > it



      P P os' uk
      H D en Sc
            t



It's getting better.

5.4 is on it's way and it's bringing some fixes for major
  pain points.
Ds so
                     ius n
                      c i


                  Qusos
                    etn?
                      i
                  C m et
                   o m n?
                        s

     P P os' uk
     H D en Sc
           t



Please be gentle.

More Related Content

Similar to PHP Doesn't Suck - Notes

Design "user experience" centric applications
Design "user experience" centric applicationsDesign "user experience" centric applications
Design "user experience" centric applicationsLuca Foppiano
 
Using TypeScript at Dashlane
Using TypeScript at DashlaneUsing TypeScript at Dashlane
Using TypeScript at DashlaneDashlane
 
Paoli company profile 2012
Paoli company profile 2012Paoli company profile 2012
Paoli company profile 2012Dino Paoli Srl
 
apidays Paris 2022 - Why you shouldn't trust me, Keerthana Ganesh (AWS) & Shu...
apidays Paris 2022 - Why you shouldn't trust me, Keerthana Ganesh (AWS) & Shu...apidays Paris 2022 - Why you shouldn't trust me, Keerthana Ganesh (AWS) & Shu...
apidays Paris 2022 - Why you shouldn't trust me, Keerthana Ganesh (AWS) & Shu...apidays
 
Douban intro english
Douban intro englishDouban intro english
Douban intro englishVIPSMedia
 
Demonolithing The Monolith? Bullocks!
Demonolithing The Monolith?  Bullocks!Demonolithing The Monolith?  Bullocks!
Demonolithing The Monolith? Bullocks!Scott Sosna
 
Project threepresentation
Project threepresentationProject threepresentation
Project threepresentationKaren Samples
 
Put a flag on it. A busy developer's guide to feature toggles.
Put a flag on it. A busy developer's guide to feature toggles.Put a flag on it. A busy developer's guide to feature toggles.
Put a flag on it. A busy developer's guide to feature toggles.Mateusz Kwasniewski
 
Lesson outline the 21 demands
Lesson outline the 21 demandsLesson outline the 21 demands
Lesson outline the 21 demandsRyan Campbell
 
B Kinoshita - Creating biology pipelines with BioUno
B Kinoshita - Creating biology pipelines with BioUnoB Kinoshita - Creating biology pipelines with BioUno
B Kinoshita - Creating biology pipelines with BioUnoJan Aerts
 
2012 Jaguar XF For Sale NY | Jaguar Dealer Near Buffalo
2012 Jaguar XF For Sale NY | Jaguar Dealer Near Buffalo2012 Jaguar XF For Sale NY | Jaguar Dealer Near Buffalo
2012 Jaguar XF For Sale NY | Jaguar Dealer Near BuffaloWest-Herr Jaguar
 
Ceh v8 labs module 06 trojans and backdoors
Ceh v8 labs module 06 trojans and backdoorsCeh v8 labs module 06 trojans and backdoors
Ceh v8 labs module 06 trojans and backdoorsMehrdad Jingoism
 
compact-optimum_rte_training_manual.pdf
compact-optimum_rte_training_manual.pdfcompact-optimum_rte_training_manual.pdf
compact-optimum_rte_training_manual.pdfMiroslavTabakovski
 
Share point content and application lifecycle management guidance
Share point content and application lifecycle management guidanceShare point content and application lifecycle management guidance
Share point content and application lifecycle management guidanceworihuela
 
Running Puppet In Stand Alone Mode
Running Puppet In Stand Alone ModeRunning Puppet In Stand Alone Mode
Running Puppet In Stand Alone Modesarguru90
 
Evaluacion sofia serrano 6 a
Evaluacion sofia serrano 6 aEvaluacion sofia serrano 6 a
Evaluacion sofia serrano 6 asamuel0711
 
Polette cafe polette -concept presentation
Polette   cafe polette -concept presentationPolette   cafe polette -concept presentation
Polette cafe polette -concept presentationPOLETTEDUBAI
 

Similar to PHP Doesn't Suck - Notes (20)

Design "user experience" centric applications
Design "user experience" centric applicationsDesign "user experience" centric applications
Design "user experience" centric applications
 
Using TypeScript at Dashlane
Using TypeScript at DashlaneUsing TypeScript at Dashlane
Using TypeScript at Dashlane
 
Paoli company profile 2012
Paoli company profile 2012Paoli company profile 2012
Paoli company profile 2012
 
apidays Paris 2022 - Why you shouldn't trust me, Keerthana Ganesh (AWS) & Shu...
apidays Paris 2022 - Why you shouldn't trust me, Keerthana Ganesh (AWS) & Shu...apidays Paris 2022 - Why you shouldn't trust me, Keerthana Ganesh (AWS) & Shu...
apidays Paris 2022 - Why you shouldn't trust me, Keerthana Ganesh (AWS) & Shu...
 
Douban intro english
Douban intro englishDouban intro english
Douban intro english
 
Demonolithing The Monolith? Bullocks!
Demonolithing The Monolith?  Bullocks!Demonolithing The Monolith?  Bullocks!
Demonolithing The Monolith? Bullocks!
 
Project threepresentation
Project threepresentationProject threepresentation
Project threepresentation
 
Put a flag on it. A busy developer's guide to feature toggles.
Put a flag on it. A busy developer's guide to feature toggles.Put a flag on it. A busy developer's guide to feature toggles.
Put a flag on it. A busy developer's guide to feature toggles.
 
Lesson outline the 21 demands
Lesson outline the 21 demandsLesson outline the 21 demands
Lesson outline the 21 demands
 
B Kinoshita - Creating biology pipelines with BioUno
B Kinoshita - Creating biology pipelines with BioUnoB Kinoshita - Creating biology pipelines with BioUno
B Kinoshita - Creating biology pipelines with BioUno
 
2012 Jaguar XF For Sale NY | Jaguar Dealer Near Buffalo
2012 Jaguar XF For Sale NY | Jaguar Dealer Near Buffalo2012 Jaguar XF For Sale NY | Jaguar Dealer Near Buffalo
2012 Jaguar XF For Sale NY | Jaguar Dealer Near Buffalo
 
Ceh v8 labs module 06 trojans and backdoors
Ceh v8 labs module 06 trojans and backdoorsCeh v8 labs module 06 trojans and backdoors
Ceh v8 labs module 06 trojans and backdoors
 
compact-optimum_rte_training_manual.pdf
compact-optimum_rte_training_manual.pdfcompact-optimum_rte_training_manual.pdf
compact-optimum_rte_training_manual.pdf
 
YIEF-2011
YIEF-2011YIEF-2011
YIEF-2011
 
Share point content and application lifecycle management guidance
Share point content and application lifecycle management guidanceShare point content and application lifecycle management guidance
Share point content and application lifecycle management guidance
 
Running Puppet In Stand Alone Mode
Running Puppet In Stand Alone ModeRunning Puppet In Stand Alone Mode
Running Puppet In Stand Alone Mode
 
Fedena - School ERP
Fedena  - School ERPFedena  - School ERP
Fedena - School ERP
 
DevOps introduction
DevOps introductionDevOps introduction
DevOps introduction
 
Evaluacion sofia serrano 6 a
Evaluacion sofia serrano 6 aEvaluacion sofia serrano 6 a
Evaluacion sofia serrano 6 a
 
Polette cafe polette -concept presentation
Polette   cafe polette -concept presentationPolette   cafe polette -concept presentation
Polette cafe polette -concept presentation
 

Recently uploaded

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clashcharlottematthew16
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek SchlawackFwdays
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024The Digital Insurer
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxNavinnSomaal
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentationphoebematthew05
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Wonjun Hwang
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 

Recently uploaded (20)

Powerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time ClashPowerpoint exploring the locations used in television show Time Clash
Powerpoint exploring the locations used in television show Time Clash
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
"Subclassing and Composition – A Pythonic Tour of Trade-Offs", Hynek Schlawack
 
My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024My INSURER PTE LTD - Insurtech Innovation Award 2024
My INSURER PTE LTD - Insurtech Innovation Award 2024
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptxSAP Build Work Zone - Overview L2-L3.pptx
SAP Build Work Zone - Overview L2-L3.pptx
 
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort ServiceHot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
Hot Sexy call girls in Panjabi Bagh 🔝 9953056974 🔝 Delhi escort Service
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
costume and set research powerpoint presentation
costume and set research powerpoint presentationcostume and set research powerpoint presentation
costume and set research powerpoint presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
Bun (KitWorks Team Study 노별마루 발표 2024.4.22)
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 

PHP Doesn't Suck - Notes

  • 1. P P os' uk H D en Sc t This is a presentation about PHP. If you are looking for a fight, leave now.
  • 2. Wh ae o? o r yu Jh H b s on ob - ee p r t a C er D vl e a Wh t he o - jhb s @m o b -ts /iu. m jhb s hp: ghb o / o b t/ t c m -t: vl t ce r/ hp /e e ah. g t/ v c o P P os' uk H D en Sc t 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.
  • 3. P P uk H Scs TP A Y N K D TYM _A MA I E U O A I M_ g t l s = g tp ( e c s ) > e ye) _a ( t P P9 6 F4 4 8 1 2A 6 - A 0 1 C 4 H E 5 83 - 2 - d -7 9 0 A 0 A F 2 D 1 0 sr & ary ot $ r ) ( a w wppa nscm w . sd es o h . P P os' uk H D en Sc t 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.
  • 4. P P uk H Scs LwB re T Et o ar ro n y i r We k o m ny a C m ui t G o lC p - s o g -o y at e P e NH I “ t edI i yu ifd h to r o erw I h n tn o wli t yu h m go n n e hk ln a s a f m w r h sae yuie n a gaai m lr e ok a svd o t a d g rvtn la m o a d o ed p i a ee po ut -am s n yu n u wt b tr rd c” R s u h t . hp/t sed rcm aci s3 - e orm w r- P Cf m w r.m t: o .rofo /r v / 8 h- -a e ok H - -a e ok tl t / yl . he T nf P MV r h P P os' uk H D en Sc t 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.
  • 5. Ia w i cn re t t r lcd i e ie o en rb ayaga e n l ug. n - Me P P os' uk H D en Sc t 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?
  • 6. Mai I oSc k g t tuk n N Lan h Ln u g e r te a g a e hp /h . t a u l t : p pn / na t/ em P P os' uk H D en Sc t 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?
  • 7. Mai I oSc k g t tuk n N TsY u C d et o r o e h p/ww .m l et r/ t: t / ws pe sog i t . ht: w .h u i e t / wwp p n . / p/ td ht: q .h . t reet h t / ap pn / i -sp p p/ e w tt . P P os' uk H D en Sc t 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.
  • 8. Mai I oSc k g t tuk n N N L E DT O I EI V S ( ot ) m sy l C P TA O WOR S I E T P P AI R N S K F WI H N H P P os' uk H D en Sc t 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.
  • 9. Mai I oSc k g t tuk n N S ae B sae h r & e h rd Gt b iu h S - hp/ i ulo /h j ) P R0(t : t y rcm y 6y d t /n . d P P os' uk H D en Sc t 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)
  • 10. Mai I oSc k g t tuk n N H v ASy a e tle hp / w .ei i. gwk Maul o i _ovnos t: w wm d wko / i/ naC d g cnetn t/ a ir i : n i P P os' uk H D en Sc t 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.
  • 11. Mai I oSc k g t tuk n N T Te E L r h RP y jhbsCrei:$pph mob@odla~ hs Satn pp trig h tp ''o 'ep t seisrcin &faue ye h r hl' o e ntutos etrs pp eh "hhi" h> co O a!; O hi h a! pp icue"etpp; h> nld ts.h" pp wo(; h> ha) ll fntos1 o, ucin!! pp h> jhbsCrei:$ mob@odla~ ht: w .h s.r/ t / wwp ph g p/ o P P os' uk H D en Sc t 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.
  • 12. Mai I oSc k g t tuk n N Ra C d ed o e ( c d goh ra g a e! I l i te ln u g s nu n ) P P os' uk H D en Sc t 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.
  • 13. UE S A F A WOR R ME K (i: o Zn) Hn N t ed t P P os' uk H D en Sc t 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:
  • 14. Ue F m w r s A r e ok a - MV H C - sf hl r Ue le es u p -u e fx l Sp rl ie eb - ra m dl ss m G e t o u syt e e - ra m dl G et o u s e hp /oaarm w r og t: khnf e ok r/ t/ a . P P os' uk H D en Sc t 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.
  • 15. Ue F m w r s A r e ok a nmsaeapcnrles aepc potolr; casPssotolretnsihucinCnrle { ls otCnrle xed ltimatootolr pbi fnto idx){ ulc ucin ne( rtr ary'o'= 'a' 'il'= 'ot'; eun ra(fo > br, tte > Pss) } } hp /tfm / t: l i.e t/ i y h P P os' uk H D en Sc t Another cool one is Lithium. It's very “leading edge” and uses namespaces like they are going out of style.
  • 16. Ue F m w r s A r e ok a Suk kn / Iiilz / ntaie $ =nwSuk) s e kn(; / Adarue / d ot $-gt s>e( 'h(<ae), /i/nm>' fnto (&s $ae=“ol”){ ucin $, nm wrd $-bd =“el $ae" s>oy Hlo nm!; } ); / Rni! / u t $-rn) s>u(; hp: ghb o / hb sSuk ts /iu. m j o b/kn t/ t c m P P os' uk H D en Sc t 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.
  • 17. S. o. . P P os' uk H D en Sc t So. Those are my thoughts on how to write better PHP. As for the language itself...
  • 18. I G t g ee t ei B tr ' t s n t 54 . -t: w wpp e m na e/ n ug. p .as h hp / w . . t a ul nl ga e o 5t i. p t/ hn/ / a o r tp ( as > x s T i = Min) rt i -t: s . p e v w cv w rvi &eio= 1 6 1 hp /v p . t i v?i =eio rvi 33 4 t/ n h n / e e sn sn (hrAry yt : “” > b ] Sot r Sn x[a = “” ) a a -t: nw . p e ppn ra /5 9 hp /e s h. t h.t nl 5 2 3 t/ p n / ie s (V = g) SN > it P P os' uk H D en Sc t It's getting better. 5.4 is on it's way and it's bringing some fixes for major pain points.
  • 19. Ds so ius n c i Qusos etn? i C m et o m n? s P P os' uk H D en Sc t Please be gentle.