May17,2007HyattRegencyChicago,IllinoisAaronWormusHedgeCoNetworks@hedgeco.netMovingtoPHP5withStyleMay17,2007HyattRegencyChicago,Illinois2Whatwewilltalkabout•HistoryofPHPUpgrades•BenefitsofPHP5•WhyyouwanttoUpgrade•CommonIssues•5StepstoStylishUpgradesMay17,2007HyattRegencyChicago,Illinois3WhoRunsPHP4inProduction?May17,2007HyattRegencyChicago,Illinois4WhoRunsPHP5inProduction?May17,2007HyattRegencyChicago,Illinois5HistoryofPHPUpgrades:PHP3•Faster–LessMemory•NewPHPDelimiterTags•Numericstringconversionwhenusingthe+operator•ChangeinConditionalstatementSyntax•Standardizationinfunctionreturnvalues•TherewasascripttoeasethetransitionMay17,2007HyattRegencyChicago,Illinois6HistoryofPHPUpgrades:PHP4•LookMom,NewEngine•ParserChanges•ErrorReporting•TypeJuggling•Streams•ZE2ReferencingIssuesMay17,2007HyattRegencyChicago,Illinois7HistoryofPHPUpgrades:PHP5•NewObjectModel–Objectreferencing•DefineClassesbeforeinstantiating•Noreassigning$this•array_merge()andfriends•ReplaceCGIwithCLI•NoMysqlBundled•varreplacedwithPPP(thenunreplaced)May17,2007HyattRegencyChicago,Illinois8HistoryofPHPUpgrades:PHP5.1•Referencehandlingissues–•Abstractprivatemethodsremoved•RedefinitionofClassconstantsremoved•SQLite3•FileClass•DateMay17,2007HyattRegencyChicago,Illinois9HistoryofPHPUpgrades:PHP5.2•Newerrormessages•Extensionchanges–Bzip2–Datetime–SPL–Zip•andmoreMay17,2007HyattRegencyChicago,Illinois10UpgradeHelpishere!“Putitonalinuxbox,rungccandseewhathappens”May17,2007HyattRegencyChicago,Illinois12ButdoesrunningPHP5meanyouhaveaModernWebApplication?May17,2007HyattRegencyChicago,Illinois13PHP5givesusthetoolsXML•SimpleXML•XMLReader/XMLWriterDataAccess•PDO•SDO•MySQLi•SQLiteSecurity•ext/FilterOOGoodness•SPL/Iterators•NewObjectmodel•PPP/ClassConstants/TypeHinting/Magicmethods•ExceptionsWebServices•Soap•json_*May17,2007HyattRegencyChicago,Illinois14Whatbusinessescareabout•CostEffectiveMaintenance•PredictableDevelopmentCycles•Creatingacodebaseonwhichprogrammersenjoyworking•Createaproductthatwilladdvaluetothecompany•Usetechnologiesthatwillbenefitthecompany’sbottomlineMay17,2007HyattRegencyChicago,Illinois15InimplementationPhasethismeans…•UnitTested–Noneedtodelayalaunchbecauseacodeadditionbrokeanotherpartofthesystem•Documented–Enablenewrecruitstoeasilystartworkingonacodebase.•Modular–Enablemultiplepeopletoworkonthesamecodebaseatthesametime•RunningPHP5–AllowyoutodeploynewtechnologiesquicklyMay17,2007HyattRegencyChicago,Illinois163FlavorsofCodeLegacySystemSpaghettiCodeOverlyObjectOrientedHappilyHybrid(++)May17,2007HyattRegencyChicago,Illinois17SpaghettiCode•CodethatwasmigratedfromPHP3toPHP4•Littleifanyseparationfrombusinessandpresentationlogic.•Lotsofredundantcode.•Littleuseofmoderntechnology(Webservices,XML,etc).•Lotsofrun-aroundcode,manualxmlhandlingcode,uglydatabaselibraries,securityissues.•Example:osCommerce,PHPNuke.May17,2007HyattRegencyChicago,Illinois18Howdowecleanthisup?•Determinereusablecomponantswithintheexistingcode.•Createclasseswhichabstractthefunctionalityoutoftheexistingcodebase.•Findclassesthatalreadyprovidethisfunctionality(ezComponants,PEAR)•CreateUnittestsfortheclasses&possiblybrowsercompatibilitytestsforfrontendtesting.•ThiscanbecompletedonanincrementalbasisLegacyCodeORMACLsSessionSeleniumPHPUnitTestSuiteMay17,2007HyattRegencyChicago,Illinois19OverlyObjectOrientedCode•Codethatwasre-writtenwhenPHP4wasreleased.•FocusonObjectOrientation.•OverlyComplexCode•Slow•Difficulttomakechangestothelowerlevelsystemwithoutbreakingtheentireplatform.•Example:eZpublish,othercontentmanagementsystemswhichhavecomeandgoneMay17,2007HyattRegencyChicago,Illinois20Howdowecleanthisup?•Theremaynotbeaproblem•Ifthereareproblems,theymaybeshowstoppers.•RefactoringOOcodeiseasy•ProvidingyouhaveastableandunittestedAPISteps:•StandarizeAPI•CreatemissingUnitTests•FixanyPHP5issuesinthecode.May17,2007HyattRegencyChicago,Illinois21HappilyHybrid•Codewhichwantstodotherightthing•NocodingStandards•Alotofcode,varyingquality•Someunittests,somedocumentation•Usuallyrunwellenoughtodiscourageanyonefromtouchingthem•MostCorporatesystemsareconsistofthistypeofcode•Hybrid++canalsobesystemslikeWordpressordrupalwhichmaintainaproceduralcodebasewhichMay17,2007HyattRegencyChicago,Illinois22Howdowecleanthisup?•Documenttheexistingcodeandprocesses•Ensureoptimumcodereuse,withagoodclassheirarchy.•UnittestyourclassesThecodewillnowruninPHP5andfulfiltherequirementsforbeingaModernWebApplicationAtafuturepointyoucanoptionally•Implementafrontcontrollerforeaseofuseandmanagement•MovetoafullyOOMVCishframeworkMay17,2007HyattRegencyChicago,Illinois23WhenIcan’tupgrade•Legacylibraries•Customextensions•Unmaintainablecode•AServiceOrientedArchitecturecanhelp!Legacy/HeterogeneousSystemUnitTestsIntegrationofthirdpartylibr