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!
Those are the opening and closing codes.PHP Code:<?php
?>
That is a basic structure of a class. We'll go ahead dumbing the variables.PHP Code:<?php
class Test //You may use anything instead of test.
{
// Methods and properties are entered here for this class!
}
?>
So if you execute this, you'll get this display.PHP Code:<?php
class Test
{
}
$obj = new Test;
var_dump($obj);
PHP Code:object(Test)#1 (0) { }
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 Code:<?php
class Test {
}
$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 Code:<?php
class Test {
public $prop1 = "I can be anything you like!"
}
$obj = new Test;
So, if you execute it, your display would be:PHP Code:<?php
class Test {
public $prop1 = "I can be anything you like!"
}
$obj = new Test;
echo $obj->prop1
Give me a like/rep if you find this useful! I'll return like/rep as well!PHP Code:I can be anything you like!
![]()


Reply With Quote



