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.
That is a basic structure of a class. We'll go ahead dumbing the variables.
So if you execute this, you'll get this display.
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.
So the above codes add that $prop1 variable which is public and now we'll be showing it in OOP method.
So, if you execute it, your display would be:
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:
<?php
?>
Those are the opening and closing codes.
PHP:
<?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:
<?php
class Test
{
}
$obj = new Test;
var_dump($obj);
So if you execute this, you'll get this display.
PHP:
object(Test)#1 (0) { }
PHP:
<?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:
<?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:
<?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:
PHP:
I can be anything you like!
Give me a like/rep if you find this useful! I'll return like/rep as well!