-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathobjects.php
More file actions
32 lines (26 loc) · 907 Bytes
/
objects.php
File metadata and controls
32 lines (26 loc) · 907 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
class Objects
{
protected $object = array();
function __set($name, $value)
{
$this->object[$name] = $value;
}
function __get($name)
{
return is_callable($this->object[$name]) ? $this->object[$name]($this) : $this->object[$name];
}
}
$object = new Objects();
$object->exampleInteger = 1;
$object->exampleString = "Hello World";
$object->exampleBoolean = true;
$object->exampleFloat = 3.14;
$object->exampleObject = new stdClass();
$object->exampleObject->stringValue = "stdClass Object";
var_dump($object->exampleInteger); # Output: int 1
var_dump($object->exampleString); # Output: string 'Hello World' (length = 11)
var_dump($object->exampleBoolean); # Output: boolean true
var_dump($object->exampleFloat); # Output: Float: 3.14
var_dump($object->exampleObject->stringValue); # Output: public 'stringValue' => string 'stdClass Object' (length=15)
?>