1<?php
2class Fruit {
3 public $name;
4 public $color;
5
6 function __construct($name, $color) {
7 $this->name = $name;
8 $this->color = $color;
9 }
10 function get_name() {
11 return $this->name;
12 }
13 function get_color() {
14 return $this->color;
15 }
16}
17
18$apple = new Fruit("Apple", "red");
19echo $apple->get_name();
20echo "<br>";
21echo $apple->get_color();
22?>
1class Bike {
2 function Bike() {
3 $this->type = 'BMX';
4 }
5}
6
7$blackSheep = new Bike();
8
9print $blackSheep->type;
1
2<?php
3class Foo {
4 public $aMemberVar = 'aMemberVar Member Variable';
5 public $aFuncName = 'aMemberFunc';
6
7
8 function aMemberFunc() {
9 print 'Inside `aMemberFunc()`';
10 }
11}
12
13$foo = new Foo;
14
15function getVarName()
16{
17 return 'aFuncName';
18}
19
20print $foo->{$foo->{getVarName()}}();
21
22