本文整理匯總了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";