本文整理匯總了PHP中foo::getValue方法的典型用法代碼示例。如果您正苦於以下問題:PHP foo::getValue方法的具體用法?PHP foo::getValue怎麽用?PHP foo::getValue使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類foo
的用法示例。
在下文中一共展示了foo::getValue方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: func
$d = 10;
$d = func($a, $b);
exit;
}
if ($which == 1) {
/**
* 返回引用示例1
*/
class foo
{
public $value = 20;
function &getValue()
{
return $this->value;
}
}
$obj = new foo();
$value =& $obj->getValue();
// test 2:
$obj->value = 30;
echo $value;
exit;
// test 1:
$value = 30;
echo $obj->value;
exit;
}
$a = '100';
$b =& $a;
$b = 200;
echo $a;
示例2: foo
//1
echo $b . '<br/>';
l($b);
//7
echo $b . '<br/>';
class foo
{
public $v = 42;
public function &getValue()
{
//返回的引用
return $this->v;
}
}
$o = new foo();
$m =& $o->getValue();
//引用的綁定
$o->v = 2;
// $m =2;
echo $m . '<br/>';
// 注意:
// 如果試圖通過return ($this->v) 這種形式來返回,會不起作用並報錯。
// 因為這是試圖返回一個表達式的結果而不是一個引用的變量。
/***
pointer |value|variable
1 |NULL |
2 |NULL |
3 |NULL |
4 |NULL |
5 |NULL |
示例3: foo
foo($a);
echo $a . '<br />';
function &bar()
{
$a = 3;
return $a;
}
class foo
{
public $value = 42;
public $name = 'Andi';
public function &getValue()
{
return $this->value;
}
public function &getName()
{
return $this->name;
}
}
$obj = new foo();
$myValue1 =& $obj->getValue();
$myValue2 = $obj->getValue();
echo $myValue1 . ':' . $myValue2 . '<br />';
$obj->value = 2;
echo $myValue1 . ':' . $myValue2 . '<br />';
$myName1 =& $obj->getName();
$myName2 = $obj->getName();
echo $myName1 . ':' . $myName2 . '<br />';
$obj->name = 'Cooler Typ';
echo $myName1 . ':' . $myName2 . '<br />';
示例4: foo
require_once '../../includes/header.php';
?>
<pre>
<?php
//Do not use return-by-reference to increase performance
class foo
{
public $value = 42;
public function &getValue()
{
return $this->value;
}
}
$obj = new foo();
$myValue =& $obj->getValue();
// $myValue is a reference to $obj->value, which is 42.
$obj->value = 2;
echo $myValue . "\n";
// prints the new value of $obj->value, i.e. 2.
//To use the returned reference, you must use reference assigment:
function &collector()
{
static $collection = array();
return $collection;
}
$collection =& collector();
//you must use reference assigment
$collection[] = 'foo';
var_dump($collection);
//To pass the returned reference to another function expecting a reference you can use this syntax: