• There is NO official Otland's Discord server and NO official Otland's server list. The Otland's Staff does not manage any Discord server or server list. Moderators or administrator of any Discord server or server lists have NO connection to the Otland's Staff. Do not get scammed!

Php oop

Nikkster

Programmer
Joined
May 9, 2008
Messages
2,848
Reaction score
9
Location
Confidential
Hi there,

I am really sorry for not keeping my PHP tutorials up to date. Reason to this is, lack of time due to own projects, school, etc.

As to compensate this, I was thinking that I would teach you some basic PHP OOP, that you'll be able to build powerful code with, if you fully understand it. The first we are going to look at is, what is OOP?

OOP stands for Object Oriented Programming.

Now we are going to build a "code based shop". It looks like this:

PHP:
<?php
class shopProducts() 
{
function __construct ( $title, $firstname, $Mainname, $price)
{
public $title = "default product";
public $producerMainName = "Main name";
public $producerFirstName = "First name";
public $price = "€10";

function getProducter() 
{
return "{$this->producerFirstName}"." {$this->producerMainName}";
   }
}
?>
If you have short_tags enabled, you can also use <? instead of <?php.

First we gather functionality into the class, saving effort and dublication in the code that uses it. The __construct() method is invoked when an object is created using the new operator. So all arguments made are being supplied to the constructor. Then we are making the code public, so everyone will be able to take advantage of it, setting name, price, etc. Then we yet create another function that will get the producerFirstName and as well as his/her mainname and return the results of that.

This is just basic, however, I will post a much longer tutorial next time. I just wanted you to know what OOP is and how it looks like.

Best Regards,
Nikkster
 
Back
Top