Attendee Survey● Are you developing applications in PHP? – Which version? Which Platform(s)? – Are you using a framework?● What other languages are you using?● Are you testing your PHP applications? – Unit testing? Browser integration testing?
PHPs Image Problem● Language origins● Deprecated features● Disorganized/disparate community● Poor release-planning● Persistent myths● Bad code (in high-profile applications)● New features are not well known● Some legitimate concerns (threads, enforced security policies, naming / param consistency)
PHP Myths● OOP is difficult or impossible ● Not a “real” programming language – a preprocessor● Performance problems ● Insecure● Windows is a second-class citizen ● All “blog code”● Community in decline ● Immature platform or only immature● Difficult/Impossible to separate applications responsibilities (view-code littered with business logic) ● Poor garbage collection● Not testable ● Tools are outdated● Tools are focused on the document-web ● Everything is global ● Fate of the language is tied to the fate of● No longer needed given client-side state mod_php● Dumb PHP “features” get in the way ● No modern language features● New deployment methods are not ● Not enterprise-friendly available (e.g. Heroku) ● Difficult to add contributions● Poorly-managed releases, slow release cycle ● No visibility of roadmap
Valid Criticisms● Naming / parameter consistency*● Multi-byte strings can cause problems*● Threading*● Few “forced” conventions*● PHP is rarely “first to feature”*● ???
PHP is constantly evolving● Release / cultural changes● Feature removal● New PHP features● New PHP tools● Second generation frameworks● New external tools
Release / core development changes● New developers on the core team● New RFC process● Reworked community resources● Feature-release timetable, ~1 year● Bugfix / maintenance timetable● Bug reporting improvements, reworked documentation approval process● Clearer expectations, more development visibility, smoother release transitions, greater predictability● Larger, more diverse developer community and a more experienced security team● Inter-framework cooperation & standards organizations
Framework Interop● http://php-fig.org● Growing influence, with three standards● PSR-0 – Autoloading/namespacing● PSR-1 – Basic coding standard● PSR-2 – Thorough style-guide● More coming....
Feature removal● Removal of some of the features caused the worst code offenses and security / predictability problems – Magic Quotes – register_globals – safe_mode – outdated mysql functions
New Features – PHP 5.0 – 5.3● Improved inheritance model● Namespaces● PDO● Closures● Phar● Exceptions● SPL work / extensions improvements● Late static binding● Garbage collector improvements
Namespaces ● Encapsulate Classes, Interfaces, Functions, Constants, Traits ● Provide grouping, prevent collisions, allow aliasing ● Encourage segregation of code ● Replace hackish alternatives ● Compile-time, not runtime
PDO● PHP Data Objects● “data-access” abstraction layer● Provide for object-oriented database access● Encourage prepared statements:
Phar● Single-file PHP archive● Executable package● Can access assets within and outside itself● phar:// stream wrapper available
Closures / Lambda functions● Hijacked from functional languages● More efficient than create_function()● Very useful for sort(), array_map(), array_filter(), or function using a callback parameter.
Garbage Collection / Late Static Binding /Performance and memory enhancements● Efficiency gains● Dont try to outsmart the compiler
New Features – 5.4● upload progress ● $this in closures● binary notation ● callable typehint● array short syntax ● jsonSerializable● array dereferencing interface● class member access ● short echo tag always on instantiation available● indirect method call by ● built-in webserver array var ● traits
Built-in webserver● Easy / no configuration in most environments● Development-only● To start: php -S localhost:8000● Provides many server environment variables● Configuration php.ini, port, docroot can be changed at execution
Traits● Horizontal code-reuse (cf. mixins)● “Compiler-assisted copy and paste”● Obey most class behaviors, but cannot be instantiated
● Traits can be composed of other traits● Aliasing and collision prevention with as and insteadof● Multiple traits can be used at once
New Features – 5.5● Password API● Setters / Getters● Generators● Intl improvements● array_column()● Fully-qualified class names● Try / Catch / Finally● Parameter skipping● Read-only properties● Named Parameters?
Generators● Simpler method for working with iterators● Nearly identical to the python implementation
Second Generation Frameworks● Post-PHP v. 5.3 – Symfony 2+, ZendFramework 2.0, Silex, (Lithium? CakePHP 2+ ?)● More modular than predecessors● Compliant with PHP-FIG (PSR-0)● Use modern PHP extensions, testing tools, OOP, abstraction layers
Create a bundle: the easy way● Generates: – template skeleton – resource directories – appKernel registry – unit test skeleton – bundle definition class – default controller● multiple routing options
Run the app● Start / visit webserver – app/console server:run● Navigate to your route to see the response – e.g. http://localhost:8000/app_dev.php/yourRoute/yourParameter● How is this better than non-framework PHP?● How is this better than existing (first-generation) frameworks?