#!/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', new stdclass());
// add a child key even the parent doesn't exist.
helper::setMember('obj', 'home.address.postcode', '10000');
// three level.
echo $obj->user->name . "\n";
echo $obj->user->age . "\n";
print_r($obj->home->address);
Ejemplo n.º 2
0
 /**
  * Set the value of a member. the member can be the foramt like db.user.
  * 
  * <code>
  * <?php
  * $lang->set('version', '1.0); 
  * ?>
  * </code>
  * @param   string  $key    the key of the member, can be father.child
  * @param   mixed   $value  the value
  * @access  public
  * @return  void
  */
 public function set($key, $value)
 {
     helper::setMember('lang', $key, $value);
 }
#!/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);
Ejemplo n.º 4
0
 * @link        http://www.zentao.net
 * @license     http://opensource.org/licenses/lgpl-3.0.html LGPL
 */
include '../../helper.class.php';
$config = new stdClass();
/* 测试一维属性的修改。*/
$config->user = '******';
helper::setMember('config', 'user', 'chunsheng');
echo $config->user . "\n";
/* 赋值的变量含有单双引号。*/
$config->name = 'wwccss';
helper::setMember('config', 'name', "wang'chun\"sheng");
echo $config->name . "\n";
/* 赋值的变量为一个数组。*/
$config->users = array(1, 2, 3);
helper::setMember('config', 'users', array('a', 'b', 'c'));
print_r($config->users);
/* 赋值的变量为一个对象。*/
$config->obj = array(1, 2, 3);
helper::setMember('config', 'obj', new stdClass());
print_r($config->obj);
/* 测试二维属性的修改。*/
$config->db->host = 'localhost';
$config->db->user = '******';
$config->db->param = array();
helper::setMember('config', 'db.host', "localhost");
helper::setMember('config', 'db.user', "chunsheng'.wang");
helper::setMember('config', 'db.param', array('1', '2', '3'));
echo $config->db->host . "\n";
echo $config->db->user . "\n";
print_r($config->db->param);
Ejemplo n.º 5
0
#!/usr/bin/env php
<?php 
/**
 * 测试array2Object方法。
 *
 * @copyright   Copyright 2009-2010 青岛易软天创网络科技有限公司(www.cnezsoft.com)
 * @author      chunsheng.wang <*****@*****.**>
 * @package     Testing
 * @version     $Id$
 * @link        http://www.zentao.net
 * @license     http://opensource.org/licenses/lgpl-3.0.html LGPL
 */
include '../../helper.class.php';
$array['a1'] = '1';
$array['a2'] = '2';
$array['a3']['b1'] = '3';
$array['a3']['b2'] = '4';
$array['a4']['b3']['c1'] = '5';
$array['a5'] = '6';
$array['a6']['b4'] = '7';
$array['a7']['b5']['c2'] = '8';
$config = new stdClass();
eval(helper::array2object($array, 'config'));
print_r($config);
echo $config->a3->b1;
echo "\n";
helper::setMember('config', 'a3.b1', 10);
echo $config->a3->b1;
echo "\n";