Home > Programming > PHP Tutorial



OO Programming in PHP.key

Sort Desciption:

Object Oriented. Programming in. PHP. CMPS 183 Hypermedia and the Web ... PHP reserves the variable $this to. refer to the object whose context the ...



Content Inside:

OO Programming in PHP.keyPage 1Object Oriented Programming in PHPCMPS 183 Hypermedia and the WebMay 1 2006Mark Slatermslater@soe.ucsc.eduPage 2Object Oriented Basics OO programs consist of hierarchies andwebs of Classes. Classes contain data and functions that act on that data. Classes can be extended through inheritance (hierarchy). Classes can contain other classes (web).Page 3A Sample PHP Class<?phpclass ImgTagGenerator{function makeImgTag( $location ){if( isset( $location ) && ( strlen( location ) > 0 ) ){echo "<IMG src="" . $location . ""> ";}else{echo "&nbsp;<!Image location not specified!> ";}}}?>Page 4$this PHP reserves the variable $this to refer to the object whose context the function was invoked from. Usually $this refers to the object the function belongs to.Page 5$this<?phpclass A{public $num;function __construct( $num ){$this>num = $num;}function getNum(){return( $this>num );}}class B{public $num;function __construct( $num ){$this>num = $num;}function getNum(){return( $this>num );}function getANum(){return( A::getNum() );}}$a = new A( 5 );$b = new B( "six" );echo "A num = " . $a>getNum() . "<br> ";echo "B num = " . $b>getNum() . "<br> ";echo "A num from B = " . $b>getANum() . "<br> ";?>Page 6$this The context in the getANum()function is Bs. When AsgetNum() functionis called statically the context does notchange.class B{...function getANum(){return( A::getNum() );}}Page 7Creating and Assigning Objects Just like Java C++ and other OO languages PHP has a new operator thatcreates instances of classes. Assigning a variable containing an object to another variable makes a copy. Assigning a reference to another variable does not.Page 8Creating and Assigning Objects<?phpclass A{public $num;function __construct( $num ){$this>num = $num;}function getNum(){return( ...

Source: www.cse.ucsc.edu


add to Google Reader add to Google Bookmark add to bloglines add to newsgator add to FURL add to digg add to webnews add to Netscape add to Yahoo MyWeb add to spurl.net add to diigo Bookmark newsvine Bookmark del.icio.us Bookmark @ SIMPIFY Bookmark MISTER WONG Bookmark Linkarena Bookmark icio.de Bookmark oneview Bookmark folkd.com Bookmark yigg.de Bookmark reddit Bookmark StumbleUpon Bookmark Slashdot Bookmark blinklist Bookmark technorati add to blogmarks add to blinkbits add to ma.gnolia add to smarking.com add to netvouz add to co.mments add to Connotea add to de.lirio.us
Search Terms:

 

Related Files

PHP Introduction

Filed under: Programming and PHP Tutorial
techniques used in PHP programming. Objectives. By the end of this course you will be able to:. Describe what PHP is and the ...

PHP MySQL Website Programming

Filed under: Programming and PHP Tutorial
PHP Classes (http://www.phpclasses.org/). A more general collection of PHP programming classes of varying quality often a useful to ...

Build Your Own Database Driven Website Using PHP & MySQL

Filed under: Programming and PHP Tutorial
new to you: the PHP scripting language and the MySQL relational database ...... tutorial on 146. two forms of 145. validating MIME types 205 ...

Network Programming

Filed under: Programming and PHP Tutorial
PHP Programming. 53. PHP Arrays. A very useful feature of PHP is the array ... PHP contains a zillion predefined functions to help you. programming ...

Advanced PHP Programming

Filed under: Programming and PHP Tutorial
Programming". A class constructor in PHP5 should be named. contstructor() .... php.ini. file:. After APD is installed you should enable it by setting the ...