39
GoOO->PHP[5] @FordAntiTrust

GoOO->PHP [5] at Barcamp Bangkok 2

Embed Size (px)

DESCRIPTION

GoOO->PHP [5] at Barcamp Bangkok 2

Citation preview

Page 1: GoOO->PHP [5]  at Barcamp Bangkok 2

GoOO->PHP[5]

@FordAntiTrust

Page 2: GoOO->PHP [5]  at Barcamp Bangkok 2

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)

Page 3: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 4: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 5: GoOO->PHP [5]  at Barcamp Bangkok 2

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".

Page 6: GoOO->PHP [5]  at Barcamp Bangkok 2

Object-model

PHP4 | Pass by value PHP5 | Pass by reference

Page 7: GoOO->PHP [5]  at Barcamp Bangkok 2

Object-model

PHP4

Bar

Foo

PHP5

Bar

Bar

Page 8: GoOO->PHP [5]  at Barcamp Bangkok 2

Object-model

PHP4 | Pass by value PHP5 | Pass by value

Page 9: GoOO->PHP [5]  at Barcamp Bangkok 2

Object-model

PHP4

Bar

Foo

PHP5

Bar

Foo

Page 10: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 11: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 12: GoOO->PHP [5]  at Barcamp Bangkok 2

Constructors/Destructors

• Constructor is named __construct()

• Destructor is named __destruct()

PHP5

Page 13: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 14: GoOO->PHP [5]  at Barcamp Bangkok 2

Static methods/properties

• Available outside of the object context

• can be public/private/protected

• self::$fooinstead of $this->foo

Page 15: GoOO->PHP [5]  at Barcamp Bangkok 2

Object Abstraction

• Abstract classes cannot be instantiated

Fatal error: Cannot instantiate

abstract class AbstractClassin ... on line xxx

Page 16: GoOO->PHP [5]  at Barcamp Bangkok 2

Interfaces

• Specify the methods a class has to

implement without defining how they are

implemented

• Classes may implement more than one interface

Page 17: GoOO->PHP [5]  at Barcamp Bangkok 2

Interfaces | Example

}

}

Page 18: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 19: GoOO->PHP [5]  at Barcamp Bangkok 2

Overloading

Page 20: GoOO->PHP [5]  at Barcamp Bangkok 2

Converted Object to a string

• Change string-cast behavior of an object

• Created method __toString() in your class.

Page 21: GoOO->PHP [5]  at Barcamp Bangkok 2

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)

Page 22: GoOO->PHP [5]  at Barcamp Bangkok 2

Automagic Objects

• Creating default object from empty

value.

object(stdClass)#1 (1) {

["name"]=>

string(8) "Moldovia"}

Page 23: GoOO->PHP [5]  at Barcamp Bangkok 2

Misc additions

• Exception Handling

• Type hints for objects

• Reflection API

• __autoload()

• Object Iteration

• Class Constants

Page 24: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 25: GoOO->PHP [5]  at Barcamp Bangkok 2

PHP Hoffman Framework(HMF)

http://www.thaicyberpoint.com/ford/blog/hmf/

Code Hosting

http://code.google.com/p/hoffmanframework/

Page 26: GoOO->PHP [5]  at Barcamp Bangkok 2

What

http://www.viewimages.com/Search.aspx?mid=3095718&epmid=1

Page 27: GoOO->PHP [5]  at Barcamp Bangkok 2

What

Page 28: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 29: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 30: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 31: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 32: GoOO->PHP [5]  at Barcamp Bangkok 2

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)

Page 33: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 34: GoOO->PHP [5]  at Barcamp Bangkok 2

Architecture | Rv. 2

Page 35: GoOO->PHP [5]  at Barcamp Bangkok 2

Today

Page 36: GoOO->PHP [5]  at Barcamp Bangkok 2

Rv. 3 (r84)

Page 37: GoOO->PHP [5]  at Barcamp Bangkok 2

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

Page 38: GoOO->PHP [5]  at Barcamp Bangkok 2
Page 39: GoOO->PHP [5]  at Barcamp Bangkok 2

Thank You ;)

@FordAntiTrust

http://www.thaicyberpoint.com/ford/blog

Code Hosting

http://code.google.com/p/hoffmanframework/