-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexamples.php
22 lines (16 loc) · 1.06 KB
/
examples.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
require_once __DIR__ . '/vendor/autoload.php';
// Basic
$dataObject = new \DataObject\DataObject(); // Create an object of DataObject
$dataObject->setMessage('Hello PHP'); // Even though method setMessage is not defined anywhere
echo $dataObject->getMessage(); // We still get the output as "Hello PHP"
// Default Values
$dataObject = new \DataObject\DataObject(['nuclear_code' => 12345]); // Create an object of DataObject. Notice we passed an array into the constructor
$dataObject->setMessage('Hello PHP'); // Even though method setMessage is not defined anywhere
echo $dataObject->getMessage(); // We still get the output as "Hello PHP"
echo $dataObject->getNuclearCode(); // And calling this method gives us the output as "12345" because of the default values passed in the constructor
// getData and setData
$dataObject = new \DataObject\DataObject();
$dataObject->setData('name', 'bond...james bond'); // This will save the value with the key 'name'
echo $dataObject->getData('name'); // Which we can later retrieve like this
echo $dataObject->getName(); // or this