Upload
ford-antitrust
View
3.944
Download
4
Embed Size (px)
DESCRIPTION
GoOO->PHP [5] at Barcamp Bangkok 2
Citation preview
GoOO->PHP[5]
@FordAntiTrust
About Speaker• Education
– 2003 – 2006• Bachelor of Science (Computer Science), Naresuan University, Thailand
– 1991 – 2003• High School and Junior High School, La Salle Chotiravi Nakhonsawan, Thailand
• Full-time– Web Developer at TARADdotcom
• Freelances – Software Designed & Consultant
– Database Consultant
– Web Developer with PHP
– SEO Consultant
• Other– Founder at ThaiThinkPad.com (ThaiThinkPad User Community)
– Co-Partnership & Web Developer at ThaiHi5.com
– Co-Founder at Siampod.com
– Staff and Developer at ThaiAdmin.org– Blogger at Ford AntiTrust’Blog (http://www.thaicyberpoint.com/ford/blog)
OOP in PHP series (1-4)In ThaiAdmin Magazine vol 1-4http://www.thaiadmin.org
More details
http://www.thaicyberpoint.com/ford/blog/id/508/
Article’s LicenseAttribution-Noncommercial-No Derivative Works 3.0 Unported
http://www.scribd.com/people/documents/786132/folder/14656
OO in PHP 5
• Object-model
• Comparing Objects
• Constructors/Destructors
• Visibility
• Static methods/properties
• Object Abstraction
• Interfaces
• final
• Overloading
• Converted Object to a string
• Class Constants
• Using get_class()
• Automagic Objects
• Misc additions
Object-model
PHP4
• Pass by value
• Use of references
needed almost
everywhere...
• at call time, and even
during instantiation.
PHP5
• Pass by reference
• Objects are referenced by a handle.
• objects are not any longer just 'improved arrays‘.
• new SPL extension
• Reflection
• An object with no properties is no longer considered "empty".
Object-model
PHP4 | Pass by value PHP5 | Pass by reference
Object-model
PHP4
Bar
Foo
PHP5
Bar
Bar
Object-model
PHP4 | Pass by value PHP5 | Pass by value
Object-model
PHP4
Bar
Foo
PHP5
Bar
Foo
Comparing Objects
PHP4
• results in true: when the
object's properties are the same
PHP5
• results in true: when the
object's handles are the same
Comparing Objects
PHP4
• results in true: when the
object's properties are the same
PHP5
• results in true: when the
object's handles are the
same
• object variables are
identified by same instance of the same class
Constructors/Destructors
• Constructor is named __construct()
• Destructor is named __destruct()
PHP5
Visibility
• public = all
• protected = class and subclass
• private = only the class
PHP5
Not used var (Strict Standards)
var: Deprecated. Please use the public/private/protected
modifiers in - on line xxx
Static methods/properties
• Available outside of the object context
• can be public/private/protected
• self::$fooinstead of $this->foo
Object Abstraction
• Abstract classes cannot be instantiated
Fatal error: Cannot instantiate
abstract class AbstractClassin ... on line xxx
Interfaces
• Specify the methods a class has to
implement without defining how they are
implemented
• Classes may implement more than one interface
Interfaces | Example
}
}
final
• final keyword, which prevents child
classes from overriding a method by
prefixing the definition with final. If the
class itself is being defined final then it cannot be extended
Overloading
Converted Object to a string
• Change string-cast behavior of an object
• Created method __toString() in your class.
Using get_class()
PHP4
foo
PHP5
Magical predefined constants (__CLASS__,
__METHOD__, and __FUNCTION__), get_class(),
get_parent_class() and get_class_methods() now
return the name of the classes/methods as they were declared (case-sensitive)
Automagic Objects
• Creating default object from empty
value.
object(stdClass)#1 (1) {
["name"]=>
string(8) "Moldovia"}
Misc additions
• Exception Handling
• Type hints for objects
• Reflection API
• __autoload()
• Object Iteration
• Class Constants
Ref.
• Go OO! Real-Life Design Patterns in PHP5
Stephan Schmidt, 1&1 Internet AG, International PHP2005 Conference - spring edition
- http://www.slideshare.net/schst/go-oo-reallife-design-
patterns-in-php-5/
• Migrating from PHP 4 to PHP 5Derick Rethans International PHP Conference 2004
Amsterdam, the Netherlands- http://www.derickrethans.nl/pres-breaking/talk.html
PHP Hoffman Framework(HMF)
http://www.thaicyberpoint.com/ford/blog/hmf/
Code Hosting
http://code.google.com/p/hoffmanframework/
What
http://www.viewimages.com/Search.aspx?mid=3095718&epmid=1
What
What
• Reusable design
• Application Programming Interface and Code
libraries
• Helper scripting program for build software
application
• Standard structure
• Top layer on Software Developer Technology Stack
Why
• High productivity (Speed++)
• Good Standard Code & Standard Structure
• Smooth team support
• Easy maintenance and long term support
• Don't repeat yourself (DRY)DRY is a core principle of Andy Hunt and Dave Thomas's book The Pragmatic Programmer.
• You Ain't Gonna Need It
History | Announce 0.1a rv.15
• January 6th, 2007
• http://www.thaicyberpoint.com/ford/blog/id/272/
• Like RoR
– MVC Pattern
– Routing URL (full control by mod_rewrite)
– Add-on (config by XML)
• FCKeditor,LightBox and Reflection
– Wrapper Class like Java
• PHP 4+ Support
• ASCII only
History | 0.1a rv.85
• January 20th, 2007
• Like RoR– MVC Pattern
– Routing URL (full control by mod_rewrite)
– Add-on (config by XML)• FCKeditor, PHPMailer, LightBox, HTLM Form Validation and Reflection
– Wrapper Class like Java
– Model like ActiveRecord in some features
– Multilanguage
• PHP 4+ Support
• Fixed bug
• ASCII only
• Access control list with XML
• Production App– http://shop.thaiadmin.org
History | 0.1a rv.98
• August 28th, 2007
• Like RoR– MVC Pattern
– Routing URL (full control by mod_rewrite)
– Add-on (config by XML)• FCKeditor, PHPMailer, LightBox, HTLM Form Validation and Reflection
– Wrapper Class like Java
– Model like ActiveRecord in some features
– Multilanguage
• PHP 4+ Support
• Fixed bug
• ASCII and Unicode
• Production App– http://www.wscxv.org (register form and user profile)
– http://www.tmbyip.com (register form)
History | Rv. 2 @ 1st Barcamp BKK
• Rv 2 = Revolution 2
• GO PHP 5 (5.2)
• MVC Pattern
• Cache
• Fusion– Drupal (Routing concept, config by XML)
– .NET (from Zend Framework)
– RoR (from ActiveRecord on Doctrine, Model layer = LogicModel)
– Smarty (View layer = RenderView)
• Rewrite controller (FlowComtroller)
• Access Control List with Zend_Acl
• Fully Unicode support
• Multilanguage on Extension (not build-in)
• Extension– Multilanguage , FCKeditor, PHPMailer, LightBox, HTLM Form Validation and Reflection
Architecture | Rv. 2
Today
Rv. 3 (r84)
Today | Rv. 3
Core
• Rv. 3 = Revolution 3
• PHP 5 (5.2.6)
• Base on Zend FW 1.5.3
• Reflection Control
• MVC Pattern with Components base
• Cache
• Environment Configurations– production
– development
– test
• Routing (w/mod_rewrite)
• Error Pages
• ORM (Zend_Db)– Model Validation
• Access Control List (Zend_Acl)
• Fully Unicode support (UTF-8)
• Multilanguage (gettext)
• Debug Logging
• Components– Form
– Img
– Upload
Thank You ;)
@FordAntiTrust
http://www.thaicyberpoint.com/ford/blog
Code Hosting
http://code.google.com/p/hoffmanframework/