Search
 
SCRIPT & CODE EXAMPLE
 

PHP

object oriented programming php

<?php
class Parent {
	public function __construct() {
    	echo "Parent Created
";
    }
  	public function sayHello() {
    	echo "Hello, from Parent
";
    }
  	public function eitherHello() {
    	echo "Hello, from Parent and child if desired
";
    }
}
class Child extends Parent {
	public function __construct() {
    	echo "Child Created
";
    }
  	public function sayHello() {
    	echo "Hello, from Child
";
    }
}
$p = new Parent();	// Parent Created
$c = new Child();	// Child Created
$p->sayHello(); 	// Hello, from Parent
$c->sayHello();		// Hello, from Child
$p->eitherHello();	// Hello, from Parent and child if desired
$c->eitherHello();	// Hello, from Parent and child if desired
?>
Comment

oop php

<?php
class Fruit {
  // Properties
  public $name;
  public $color;

  // Methods
  function set_name($name) {
    $this->name = $name;
  }
  function get_name() {
    return $this->name;
  }
  function set_color($color) {
    $this->color = $color;
  }
  function get_color() {
    return $this->color;
  }
}

$apple = new Fruit();
$apple->set_name('Apple');
$apple->set_color('Red');
echo "Name: " . $apple->get_name();
echo "<br>";
echo "Color: " .  $apple->get_color();
?>
 
Comment

oop php

Well Explained in here: 
https://www.androidhive.info/2012/05/how-to-connect-android-with-php-mysql/
@Zenonymous
Comment

php oop


Andomi Ansari
  <?php
class Parent {
	public function __construct() {
    	echo "Parent Created
";
    }
  	public function sayHello() {
    	echo "Hello, from Parent
";
    }
  	public function eitherHello() {
    	echo "Hello, from Parent and child if desired
";
    }
}
class Child extends Parent {
	public function __construct() {
    	echo "Child Created
";
    }
  	public function sayHello() {
    	echo "Hello, from Child
";
    }
}
$p = new Parent();	// Parent Created
$c = new Child();	// Child Created
$p->sayHello(); 	// Hello, from Parent
$c->sayHello();		// Hello, from Child
$p->eitherHello();	// Hello, from Parent and child if desired
$c->eitherHello();	// Hello, from Parent and child if desired
?>


Comment

oop php

<?php
   class Mobile {
      /* Member variables */
      var $price;
      var $title;
      /* Member functions */
      function setPrice($par){
         $this->price = $par;
      }
      function getPrice(){
         echo $this->price ."
";
      }
      function setName($par){
         $this->title = $par;
      }
      function getName(){
         echo $this->title ."
";
      }
   }
$Samsung = new Mobile();
$Xiaomi = new Mobile();
$Iphone = new Mobile();
$Samsung->setName( "SamsungS8 );
$Iphone->setName( "Iphone7s" );
$Xiaomi->setName( "MI4" );
$Samsung->setPrice( 90000 );
$Iphone->setPrice( 65000 );
$Xiaomi->setPrice( 15000 );
Now you call another member functions to get the values set by in above example
$Samsung->getName();
$Iphone->getName();
$Xiaomi->getName();
$Samsung->getPrice();
$Iphone->getPrice();
$Xiaomi->getPrice();
?>
Comment

oop in php

/* We keep data memebers private and keep functions public. And access that data memebers through functions because we cannot access private data members directly. 
    We initialize data members through Constructor. */                                      


class Calculation{
     public $a, $b, $c;
     function sum(){
         $this->c = $this->a+$this->b;                                
         return $this->c;
     }
     function sub(){
         $this->c = $this->a-$this->b;
         return $this->c;
     }
 }


 $c1 = new Calculation();                    // create an object c1.
 $c2 = new Calculation();                    // create an object c2.

 $c1->a = 40;                                // this is not a good method to access and initialize data members. We keep data memebers private and keep function public. And access that data memebers through functions. We initialize data members through Constructor.   
 $c1->b = 30;

 echo "Sum of c1 = " . $c1->sum() . "<br>";
 echo "Sub of c1 = " . $c1->sub() . "<br>";

 $c2->a = 30;
 $c2->b = 20;

 echo "Sum of c2 = " . $c2->sum() . "<br>";
 echo "Sub of c2 = " . $c2->sub() . "
";
Comment

php-oop

<?php


class My{

    public $name,$age;

    public function __construct($myName,$myAge)
    {
        $this->name = $myName;
        $this->age = $myAge;

    }
}

$me = new My("WinWinMaw",22);
//$me->name = "hhz";
//$me->age = 22;

$my = new My("Maw",20);
//$me->name = "hhz";
//$me->age = 22;

$abc = new My("abc",32);


print_r([$me,$my,$abc]);
?>


//run => php filename.php
Comment

php oops

use auth
Comment

PREVIOUS NEXT
Code Example
Php :: livewire not working 
Php :: php sort multidimensional array by value 
Php :: Add new column to table in mysql using php 
Php :: define function parameters php 
Php :: php remove and  
Php :: laravel update model from request 
Php :: Laravel Migration Error: Syntax error or access violation: 1071 Specified key was too long; max key length is 767 bytes 
Php :: php session destroy 
Php :: laravel get first letter of each word 
Php :: get data based on date in laravel 
Php :: php 
Php :: php convert string to boolean 
Php :: query php 
Php :: base64 enocode php 
Php :: show float laravel blade 
Php :: laravel range query 
Php :: Fatal error: Exception thrown without a stack frame in Unknown on line php 
Php :: get id by url wordpress 
Php :: date to string php 
Php :: Fetch Multiple Rows in PHP 
Php :: laravel observer events 
Php :: php list directory files by date 
Php :: sum row data and get all data eloquent laravel 
Php :: foreach skip current iteration 
Php :: wp get post id by slug 
Php :: spl_autoload_register 
Php :: download pdf php 
Php :: php artisan test 
Php :: getting input value in session variable in php 
Php :: laravel automatically generate unique username 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =