Object Oriented programming using PHP

Asked By 120 points N/A Posted on -
qa-featured

I am new to programming in PHP. I want to know if PHP supports Object Orientation and How can I create classes using PHP? Can anyone help me.

SHARE
Best Answer by asiri
Answered By 0 points N/A #88358

Object Oriented programming using PHP

qa-featured

PHP supports Object Orientation since the release of PHP3. Further Improvements were made by PHP 4. Since the introduction of the PHP 5 lots of the features of the Object Orientation were included. You could create a class in PHP as the following :

class <<class name>> {

<<private/public/ $property name>> // properties list

….

//method list

function <<function name>> {

}

….

}

It is same as the other Object Oriented programming. Try it out. If you have any problems leave a comment.

Answered By 0 points N/A #88359

Object Oriented programming using PHP

qa-featured

You can create classes and sub classes in PHP 5. Example is given here.

****Implementing Parent Class

class parentClass{

private $parentName;  //properties can be public, private or protected.

private $parentProperty;

private function1{ //methods also can be public, private or protected.

//statements

}

function2{

//statements

}

}

****** Implementing sub class

class childClass extends parentClass{

private $childName;

private $childProperty;

function1{

//statements

}

function2{

//statements

}

}

For more details you can refer to http://php.net/manual/en/language.oop5.php

Answered By 120 points N/A #88360

Object Oriented programming using PHP

qa-featured

Thanks guys. Can I create classes in separate files and link them together? Please let me know how to link and create the objects using it.

Best Answer
Best Answer
Answered By 0 points N/A #88361

Object Oriented programming using PHP

qa-featured

Yes it is possible. You can create a separate file for the classes you created and call using following code.

using keyword "require"

require( "class/class_db.php" );

or using keyword "include"

include("class/class_item.php");

*** It is better including each class in a separate file. By that way it is easy to modify the code.

Once you have linked the classes objects could be created using the key word "new"

$obj_item = new class_item();

For further details on creating classes and objects refer to official php site php.net/manual/en/language.oop5.php.

Answered By 0 points N/A #88363

Object Oriented programming using PHP

qa-featured

It is possible of linking the classes using the key word "include". And then work as the tutorial to create instances and use the object oriented features.

Answered By 120 points N/A #88365

Object Oriented programming using PHP

qa-featured

Thank you guys. It was great help. I think it is possible linking several classes in oe php files and use features of all the classes.

Answered By 0 points N/A #88366

Object Oriented programming using PHP

qa-featured

It is possible to link and open multiple classes in same page. Nice to see you got the answer and welcome again to the open source community.

Related Questions