Log in

View Full Version : [TUT] OOP Programming [TUT]



AaidenX
04-08-2013, 12:45 PM
First off, you must be thinking what OOP means,

O - Object
O - Oriented
P - PHP

So I think you got a rough idea, what it means.

Let's start with a bit of code!


<?php

?>

Those are the opening and closing codes.


<?php

class Test //You may use anything instead of test.
{
// Methods and properties are entered here for this class!
}
?>

That is a basic structure of a class. We'll go ahead dumbing the variables.


<?php
class Test
{

}
$obj = new Test;
var_dump($obj);


So if you execute this, you'll get this display.



object(Test)#1 (0) { }




<?php

class Test {

}
$obj = new Test;

?>

So in that, we remove the line, var_dump($obj); to stop dumping the variable, we'll be using the echo function to do so.



<?php
class Test {
public $prop1 = "I can be anything you like!"
}
$obj = new Test;


So the above codes add that $prop1 variable which is public and now we'll be showing it in OOP method.



<?php
class Test {
public $prop1 = "I can be anything you like!"
}
$obj = new Test;
echo $obj->prop1


So, if you execute it, your display would be:


I can be anything you like!


Give me a like/rep if you find this useful! I'll return like/rep as well! :)

Trinity
04-08-2013, 08:54 PM
First off, you must be thinking what OOP means,

O - Object
O - Oriented
P - PHP



OOP stands for object-oriented programming.
This is a horrible tutorial that doesn't teach anything or even explain why OOP is useful.

Zak
04-08-2013, 11:01 PM
OOP stands for object-oriented programming.
This is a horrible tutorial that doesn't teach anything or even explain why OOP is useful.

He is right lol

Java would probably be the best language to demonstrate OOP. I thought a good tutorial on OOP would start with what it means and why 'object-orientation' is important in the first place. Starting with how to start and end PHP tags.. then demonstrating a class and executing doesn't really tell you anything about OOP?

AaidenX
08-08-2013, 11:36 AM
@Trinity bro, thats what I learnt... and I shared this.. c'mon!

AbelA
24-09-2013, 01:58 PM
He is right lol
Java would probably be the best language to demonstrate OOP. I thought a good tutorial on OOP would start with what it means and why 'object-orientation' is important in the first place. Starting with how to start and end PHP tags.. then demonstrating a class and executing doesn't really tell you anything about OOP?
I agree with you. You gave more useful steps than topic starter did.

Want to hide these adverts? Register an account for free!