本文整理汇总了PHP中helper::setMember方法的典型用法代码示例。如果您正苦于以下问题:PHP helper::setMember方法的具体用法?PHP helper::setMember怎么用?PHP helper::setMember使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类helper
的用法示例。
在下文中一共展示了helper::setMember方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: stdclass
#!/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);
示例2: set
/**
* 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);
}
示例3: stdclass
#!/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);
示例4: stdClass
* @link http://www.zentao.net
* @license http://opensource.org/licenses/lgpl-3.0.html LGPL
*/
include '../../helper.class.php';
$config = new stdClass();
/* 测试一维属性的修改。*/
$config->user = 'wwccss';
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 = 'wwccss';
$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);
示例5: stdClass
#!/usr/bin/env php
<?php
/**
* 测试array2Object方法。
*
* @copyright Copyright 2009-2010 青岛易软天创网络科技有限公司(www.cnezsoft.com)
* @author chunsheng.wang <chunsheng@cnezsoft.com>
* @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";