Php code – Codemeets – 05

php codemeets 5. I will focus on Class, Construct, Object, getter,setters and Inheritance. Finally we can complete today php basic course.

Php code Class

Class is collection of objects and functions.

This is a simple mining for the class. We find a class in object oriented programming. The use of this concept revolutionized the software development industry. This made it possible to create very fast software with a small amount of code. The specialty here is the ability to reuse code. Let’s see how to use it for php. The following example shows how to declare and execute a class.

<?php
class Book {
var $name;
var $author;
var $price;               //class assing
}
$book1 = new book;
$book1 = name = "Harry Potter";
$book1 = price = "1700";          //make objects
$book1 = author = "JK";

echo $book1 -> name;
echo $book1 -> price;
?>

This code output is Harry Potter 1700.

Constructor

In class-based object-oriented programming in . I will focus on Class, Construct, Object, getter,setters and Inheritance. Finally we can complete today php basic course., a constructor is a special type of subroutine called to create an object. It prepares the new object for use, often accepting arguments that the constructor uses to set required member variables

You can get good idea using following example about php constructor.

<?php
class Book{
var $name;
var $price;
var $author;
function__construct(){
echo"this is book<br>";
}
}
$book1 = new Book;
$book2 = new Book;
?>

This code output is This is book two time print.

Object and Functions

In computer programming, a function object is a construct that allows an object with the same syntax to be called or called a normal function. Active objects are often referred to as funksters.

This is mining of the object and functions. now we can try to add it php. look below example.

<?php
class student {
var $name;
var $stream;
var $gpa;
 function__construct ($name,$stream,$gpa){
$this->name = $name;
$this->stream = $stream;
$this->gpa = $gpa;
}
function hasHonors(){
if ($this->gpa>2.5){
return "true";
}
else{
return "false";
}
}
}
$student1 = new student ("jane","Maths","3.2");
$student2 = new student ("mick","Biology","2.4");

echo $student1 -> hasHonors();
echo $student2 -> hasHonors();
?>

This code answer is true false.

Getters and Setters

get create function function getRating(){}

use if statement function setRating($rating)

Private can not be change. Public can be change.

Inheritance

Object-oriented programming, inheritance, is the mechanism by which an object or class retains a similar function based on another object or class. Also defined as taking new classes from existing classes, such as the superclass or the basic class, and converting them into a hierarchy of classes.

see below you can get idea for inheritance.

<?php
class chef{
function makechicken(){
echo "make chicken";
}
function make salad(){
echo "make salad";
}
function make bbq(){
echo "make bbq";
}
}
$italianchef = new italianchef;
echo $italiancheff->makechicken();
echo $italiancheff->makebbq();
?>
php code

output is make chicken and make bbq.

php basics done. You can see the brief description about php

PHP (Hypertext Preprocessor) is a server-side scripting language primarily used for web development. PHP creates dynamic web pages and can be embedded in HTML. It can also be used for command-line scripting and client-side GUI applications. An open-source language, PHP is supported by many web hosting services and is often used in combination with other technologies such as MySQL and JavaScript to create more complex web applications.

Now over the php basic course. you go this link and answer the quection and get php codemeets certificate. Get Certificate

Thank for all !

More php ClickHere!

Over php code meets See you Next Lesson Soon!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Translate »