Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

PHP OOP - Constructor

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

  function __construct($name) {
    $this->name = $name;
  }
  function get_name() {
    return $this->name;
  }
}

$apple = new Fruit("Apple");
echo $apple->get_name();
?>
 
PREVIOUS NEXT
Tagged: #PHP #OOP #Constructor
ADD COMMENT
Topic
Name
1+5 =