本文整理汇总了PHP中foo::bar方法的典型用法代码示例。如果您正苦于以下问题:PHP foo::bar方法的具体用法?PHP foo::bar怎么用?PHP foo::bar使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类foo
的用法示例。
在下文中一共展示了foo::bar方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bar
<?php
error_reporting(E_ALL);
class foo
{
public function bar()
{
$x = array();
$x[] = 3;
$x[] = array(1, 5);
$x[] = new foo();
return $x;
}
}
$foo = new foo();
var_dump($x = $foo->bar()[1]);
var_dump($foo->bar()[1][1]);
var_dump($x[0]);
var_dump($x = $foo->bar()[2]);
var_dump($x->bar());
var_dump($x->bar()[0]);
$x = array();
$x[] = new foo();
var_dump($x[0]->bar()[2]);
var_dump($foo->bar()[2]->bar()[1]);
var_dump($foo->bar()[2]->bar()[2]->bar()[1][0]);
var_dump($foo->bar()[2]->bar()[2]->bar()[1][0][1]);
var_dump($foo->bar()[2]->bar()[2]->bar()[4]);
var_dump($foo->bar()[3]->bar());
示例2: bar
<?php
namespace foobar;
class foo
{
public function bar(self $a)
{
}
}
$foo = new foo();
$foo->bar($foo);
// Ok!
$foo->bar(new \stdclass());
// Error, ok!
示例3: array
[expect php]
[file]
<?php
$f = 'c="foo"';
class foo
{
const foobar = 1;
public $pp = array('t' => null);
function bar()
{
echo $this->t = 'f';
}
function __get($prop)
{
return $this->pp[$prop];
}
function __set($prop, $val)
{
echo "__set";
$this->pp[$prop] = '';
}
}
$f = new foo();
$f->bar();
?>
--EXPECT--
__setf
示例4: bar
[expect php]
[file]
<?php
class foo
{
function bar()
{
$args = func_get_args();
foreach ($args as $arg) {
echo $arg;
}
}
}
$x = new foo();
$x->bar('ahoj', 13);
示例5: bar
<?php
class foo
{
function bar()
{
print "Hey there!\n";
}
}
foo::bar();
示例6: bar
<?php
class foo
{
public function bar() : callable
{
$test = "one";
return function () use($test) : array {
return null;
};
}
}
$baz = new foo();
var_dump($func = $baz->bar(), $func());
示例7: __construct
<?php
final class foo
{
public $bar;
private $foo = 0;
public function __construct($bar)
{
$this->bar = $bar;
}
public function foo()
{
return ++$this->foo;
}
public static function bar()
{
return new self(123);
}
}
$foo = new foo('azerty');
echo $foo->foo() . "\n";
echo $foo->bar . "\n";
echo foo::bar()->bar . "\n";
示例8: bar
<?php
class foo
{
public function bar() : callable
{
$test = "one";
return function () use($test) : array {
return array($test);
};
}
}
$baz = new foo();
var_dump($baz->bar());
示例9: bar
{
$this->val = 1;
}
function bar()
{
echo $this->val;
$ref =& $this;
$ref->val = 2;
echo $this->val;
$ref2 = $this;
$ref2->val = 3;
echo $this->val;
$x = new foo();
echo $x->val;
$ref3 =& $x;
$ref3->val = 4;
echo $x->val;
$ref4 = $x;
$ref4->val = 5;
echo $x->val;
}
var $val;
}
$x = new foo();
$x->bar();
$ref5 = $x;
$ref5->val = 6;
echo $x->val;
$ref6 =& $x;
$ref6->val = 7;
echo $x->val;
示例10: testfunc
[expect php]
[file]
<?php
function testfunc($var)
{
echo "testfunc {$var}\n";
}
class foo
{
public $arr = array('testfunc');
function bar()
{
$this->arr[0]('testvalue');
}
}
$a = new foo();
$a->bar();
示例11: main
function main()
{
$l = new foo();
$l->bar();
}
示例12: __construct
function __construct()
{
echo "class ok\n";
}
static function bar()
{
return "method ok\n";
}
}
function f1($x = namespace\C)
{
return $x;
}
function f2($x = namespace\foo::C)
{
return $x;
}
function f3(namespace\foo $x)
{
return "ok\n";
}
echo namespace\C;
echo namespace\foo();
echo namespace\foo::C;
echo namespace\foo::C2;
echo namespace\foo::$var;
echo namespace\foo::bar();
echo namespace\f1();
echo namespace\f2();
echo namespace\f3(new namespace\foo());
echo namespace\unknown;
示例13: bar
<?php
class foo
{
public $test = 0;
private $test_2 = 1;
protected $test_3 = 2;
public function bar()
{
try {
throw new Exception('foo');
} catch (Exception $this) {
var_dump($this);
}
$this->baz();
}
public function baz()
{
foreach ($this as $k => $v) {
printf("'%s' => '%s'\n", $k, $v);
}
print "ok\n";
}
}
$test = new foo();
$test->bar();
示例14: def_md
<?php
def_md('foo\\bar', 5, function () {
echo '.';
return "1\n";
});
def_md('foo::bar', 5, function () {
echo '.';
return "2\n";
});
echo foo\bar();
echo foo\bar();
echo foo::bar();
echo foo::bar();
?>
---
.1
1
.2
2
示例15: __construct
--TEST--
Bug #27504 (call_user_func_array allows calling of private/protected methods)
--FILE--
<?php
class foo
{
function __construct()
{
$this->bar('1');
}
private function bar($param)
{
echo 'Called function foo:bar(' . $param . ')' . "\n";
}
}
$foo = new foo();
call_user_func_array(array($foo, 'bar'), array('2'));
$foo->bar('3');
?>
--EXPECTF--
Called function foo:bar(1)
Warning: expects parameter 1 to be valid callback, cannot access in %s on line %d at pos %d
Fatal error: Call to private method foo::bar() from context '' in %s on line %d, position %d