+ add the testing scripts for helper::setMember() method.
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
value1.1
|
||||
value2
|
||||
3
|
||||
Array
|
||||
(
|
||||
[0] => 1
|
||||
[1] => 2
|
||||
[2] => 3
|
||||
)
|
||||
stdClass Object
|
||||
(
|
||||
[key1] => value2.1
|
||||
)
|
||||
@@ -0,0 +1,3 @@
|
||||
Mary
|
||||
20
|
||||
us
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
<<<TC
|
||||
title: testing the setMember method.
|
||||
TC;
|
||||
|
||||
/* Include the helper class. */
|
||||
include '../../helper.class.php';
|
||||
|
||||
/* Create two objects named obj and obj2. */
|
||||
$obj = new stdclass();
|
||||
$obj->key1 = 'value1';
|
||||
|
||||
$obj2 = new stdclass();
|
||||
$obj2->key1 = 'value2.1';
|
||||
|
||||
helper::setMember('obj', 'key1', 'value1.1'); // overide the exists key.
|
||||
helper::setMember('obj', 'key2', 'value2'); // add a new key.
|
||||
helper::setMember('obj', 'key3', 3); // set an int value.
|
||||
helper::setMember('obj', 'key4', array(1, 2, 3)); // set an array value.
|
||||
helper::setMember('obj', 'key5', $obj2); // set an object value.
|
||||
|
||||
echo $obj->key1 . "\n";
|
||||
echo $obj->key2 . "\n";
|
||||
echo $obj->key3 . "\n";
|
||||
print_r($obj->key4);
|
||||
print_r($obj->key5);
|
||||
+21
@@ -0,0 +1,21 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
<<<TC
|
||||
title: testing the setMember method with multi level.
|
||||
TC;
|
||||
|
||||
/* Include the helper class. */
|
||||
include '../../helper.class.php';
|
||||
|
||||
/* Create two objects named obj and obj2. */
|
||||
$obj = new stdclass();
|
||||
$obj->user = new stdclass();
|
||||
$obj->user->name = 'Tom';
|
||||
|
||||
helper::setMember('obj', 'user.name', 'Mary'); // overide the exists key.
|
||||
helper::setMember('obj', 'user.age', 20); // add a child key to an existing key.
|
||||
helper::setMember('obj', 'home.address', 'us'); // add a child key even the parent doesn't exist.
|
||||
|
||||
echo $obj->user->name . "\n";
|
||||
echo $obj->user->age . "\n";
|
||||
echo $obj->home->address . "\n";
|
||||
Reference in New Issue
Block a user