Answers for "To create a class in PHP, you use the class keyword to write a class definition, which contains that data members and member functions that make up the class."

PHP
7

create a class in php

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

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

$apple = new Fruit("Apple", "red");
echo $apple->get_name();
echo "<br>";
echo $apple->get_color();
?>
Posted by: Guest on July-22-2020
1

php object

$o= new \stdClass();
$o->a = 'new object';

OR

$o = (object) ['a' => 'new object'];
Posted by: Guest on November-20-2020

Code answers related to "To create a class in PHP, you use the class keyword to write a class definition, which contains that data members and member functions that make up the class."

Browse Popular Code Answers by Language