object oriented programming php
snippet in php

object oriented programming php

user9051

<?php
class Parent {
	public function __construct() {
    	echo "Parent Created\n";
    }
  	public function sayHello() {
    	echo "Hello, from Parent\n";
    }
  	public function eitherHello() {
    	echo "Hello, from Parent and child if desired\n";
    }
}
class Child extends Parent {
	public function __construct() {
    	echo "Child Created\n";
    }
  	public function sayHello() {
    	echo "Hello, from Child\n";
    }
}
$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
?>

oops concepts in php

user3960

The  PHP Object-Oriented Programming concepts are:
Class 
Objects
Inheritance
Interface
Abstraction
Magic Methods

oops concepts in php

user8914


    <?php
class Fruit {
  public $name;
}
$apple = new Fruit();
$apple->name = "Apple";
?>
 

php oop tutorial

user6339


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

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

$apple = new Fruit();

    $banana = new Fruit();
$apple->set_name('Apple');
$banana->set_name('Banana');

    
echo $apple->get_name();
echo "<br>";

    echo $banana->get_name();
?>
 

how to make php oop class

user2546

public className{
	public function __construct(){
    //CODE HERE
    }
}