As Senior Web Developer,
I am required to be technical lead within the team. This also means
making sure the technology is understood and used correctly. With this
in mind, I’ve recently noticed that many of my team-mates obviously
don’t understand the underlying concepts of OOP.
For this reason, I’ve prepared this short tutorial on the concepts – to
be followed by more detailed posts on execution in Javascript and in
PHP.
<?php
class SimpleClass
{
// define variable
public $var = 'a default value';
// method declaration
public function displayVar()
{
// calling value of variable using $this->var
echo $this->var;
}
}
// making object of class
$b = new SimpleClass();
// calling function using object////////////
$b->displayVar();
?>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Creating an instance
<?php
class SimpleClass
{
// define variable
public $var = 'a default value';
// method declaration
public function displayVar()
{
// calling value of variable using $this->var
echo $this->var;
}
}
// making object of class
$b = new SimpleClass();
// calling function using object////////////
$b->displayVar();
?>
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Creating an instance
<?php
$instance = new SimpleClass();// This can also be done with a variable:
$className = 'Foo';
$instance = new $className();
// Foo()?>
No comments:
Post a Comment
Thank you for your Comment....