本文整理汇总了PHP中MyClass::foo方法的典型用法代码示例。如果您正苦于以下问题:PHP MyClass::foo方法的具体用法?PHP MyClass::foo怎么用?PHP MyClass::foo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MyClass
的用法示例。
在下文中一共展示了MyClass::foo方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: callBar
public function callBar()
{
$this->bar();
}
public function callBaz()
{
$this->baz();
}
public function callFizzBuzz()
{
$this->fizzbuzz();
}
}
$class = new MyClass();
// Call methods directly
$class->foo();
// This be foo, foo!
$class->bar();
// This is the bar function (Tried to call bar)
$class->baz();
// The amazing baz method. (Tried to call baz)
$class->fizzbuzz(7);
// Nothing (Tried to call fizzbuzz)
echo "Calling the call functions below:\n";
$class->callFoo();
// This be foo, foo!
$class->callBar();
// This is the bar function
$class->callBaz();
// The amazing baz method.
$class->callFizzBuzz();
示例2: ClassReflector
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
use BetterReflection\Reflector\ClassReflector;
use BetterReflection\SourceLocator\Type\SingleFileSourceLocator;
use PhpParser\PrettyPrinter\Standard as CodePrinter;
// Create the reflection first (without loading)
$classInfo = (new ClassReflector(new SingleFileSourceLocator(__DIR__ . '/MyClass.php')))->reflect('MyClass');
// Override the body...!
$classInfo->getMethod('foo')->setBodyFromClosure(function () {
return 4;
});
// Load the class...!!!!
$classCode = (new CodePrinter())->prettyPrint([$classInfo->getAst()]);
eval($classCode);
$c = new MyClass();
echo $c->foo() . "\n";
// should be 4...!?!??
示例3: foo
error_reporting(E_ALL);
trait A
{
public function foo()
{
echo 'a';
}
}
trait B
{
public function foo()
{
echo 'b';
}
}
trait C
{
public function foo()
{
echo 'c';
}
}
class MyClass
{
use C, A, B {
B::foo insteadof A, C;
}
}
$t = new MyClass();
$t->foo();