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! :)
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! :)