本文整理匯總了PHP中test::add方法的典型用法代碼示例。如果您正苦於以下問題:PHP test::add方法的具體用法?PHP test::add怎麽用?PHP test::add使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類test
的用法示例。
在下文中一共展示了test::add方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: test
<?php
class test
{
public $member;
function test()
{
$this->member = 1;
register_shutdown_function(array($this, 'destructor'));
}
function destructor()
{
print __METHOD__ . "\n";
}
function __destruct()
{
print __METHOD__ . "\n";
}
function add()
{
$this->member += 1;
print $this->member . "\n";
}
}
$t = new test();
$t->add();
$t->add();
echo "Done\n";
示例2: add
<?php
class test
{
public function add($num1, $num2, $callback)
{
$sum = $num1 + $num2;
$callback($sum);
}
public function call_from_string($num1, $num2, $callbackString)
{
$sum = $num1 + $num2;
call_user_func($callbackString, array($num1, $num2, $sum));
}
}
function display_string($params)
{
foreach ($params as $key => $param) {
echo '<p>Params: ' . $key . ' = ' . $param;
}
}
$test = new test();
// pass literal callback function
$test->add(1, 1, function ($result) {
echo $result;
});
// pass callback via string
$test->call_from_string(2, 3, 'display_string');