Started working on changing code base of PHP-XKCD assignment to Object Oriented.
Came to learn a lot of practical things.
Classes with namespaces are automatically included if the namespace is perfectly organised with the directory structure.
Function chaining
can call multiple functions one after other from a class without referencing the class object again and again
For e.g.
$obj->someFunction();
$obj->someFunction2();
$obj->someFunction3();These can be instead written as
$obj->someFunction()
->someFunction2()
->someFunction3();This is known as method chaining. Can be achieved by returning the class instance in the function
class obj
{
function someFunction()
{
return $this;
}
function someFunction2()
{
return $this;
}
function someFunction3()
{
return $this;
}
}This is what i used in my PHP project
Also when we create an Object Oriented program, the initial development of the class and functions can be a bit time consuming, but at the time of implementation, it becomes so easy and faster to achieve logics.
Learned a concept of giving valuable and understanding names to things.
For e.g.
$obj->setStatus(1);Here some other person may have difficulties in knowing what is this 1 for. So instead of this, we can achieve another thing like
class Obj
{
public const VERIFIED = 1;
}
$obj = new Obj();
$obj->setStatus(Obj::VERIFIED);In this way, we can remember that the status 1 is for VERIFIED
Also a point: The Cli version of PHP & the web version of PHP Works on different configuration files.
That’s pretty much how my day today went at rtCamp, looking towards more wonderful days.
Regards
–
Aryan Jasala
WordPress Engineer Trainee
