Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

constructor in php

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

  function __construct($name) {
    $this->name = $name;
  }
  function get_name() {
    return $this->name;
  }
  function get_color() {
    return $this->color;
  }
}
$mycar = new Car("Audi");
$mycar->color = "red";

echo $mycar->get_name(); // Audi
echo $mycar->get_color(); // red
 
PREVIOUS NEXT
Tagged: #constructor #php
ADD COMMENT
Topic
Name
8+3 =