Пример #1
0
 public function testControlStructures()
 {
     if ($x) {
         foo();
     } elseif ($y) {
         bar();
     } else {
         foobar();
     }
 }
Пример #2
0
 function testFoobar()
 {
     $this->skipUnless(MOCKFUNCTION_AVAILABLE, "Function mocking not available");
     if (MOCKFUNCTION_AVAILABLE) {
         MockFunction::generate('foobar');
         MockFunction::setReturnValue('foobar', 'bar');
         MockFunction::expectCallCount('foobar', 2);
         $this->assertEqual(foobar(), 'bar');
         $this->assertEqual(foobar(), 'bar');
         MockFunction::restore('foobar');
     }
 }
Пример #3
0
var_dump($f3);
var_dump($f3 === $f4);
// true
$f4[0] = 10;
var_dump($f1);
// 10
function foobar(&$var)
{
    $var++;
}
function bar()
{
    $a = 5;
    return $a;
}
foobar(bar());
// strict
//foo(4); // fatal
$c = 5;
function &getRef()
{
    global $c;
    return $c;
}
$c1 =& getRef();
$c1++;
var_dump($c);
// 6
var_dump($c1);
// 6
function &collector()
--TEST--
Positional arguments cannot be used after argument unpacking
--FILE--
<?php 
function foobar()
{
}
foobar(...[1, 2, 3], 4);
?>
--EXPECTF--

Fatal error: Cannot use positional argument after argument unpacking in %s on line %d, position %d
Пример #5
0
<?php

/**
 * Created by PhpStorm.
 * User: Stefan
 * Date: 25/01/2016
 * Time: 11:01
 */
function foobar() : int
{
    return 50;
    // strictly type-checked return
}
echo foobar() . "\n";
echo "<br>" . "<br>";
// Integers
echo "Integers Spaceship operator <=>" . "<br>";
echo 1 <=> 1;
// 0
echo "<br>";
echo 1 <=> 2;
// -1
echo "<br>";
echo 2 <=> 1;
// 1
echo "<br>";
Пример #6
0
<?php

// x3.php
dl("x3.so");
echo foobar();
Пример #7
0
<?php

// x4.php
dl("x4.so");
echo foobar("Go! ", 3);
Пример #8
0
<?php

namespace foo {
    function bar()
    {
        return __FUNCTION__;
    }
}
namespace {
    use function foo\bar as foobar;
    use function foobar as foo_bar;
    var_dump(foobar());
    var_dump(foo_bar());
}
Пример #9
0
    echo "*";
    $var++;
} while ($var <= 5);
$s = 0;
for ($i = 0; $i < 50; $i++) {
    $d[$i] = $i * $i;
}
for ($i = 0; $i < $d . count(); $i++) {
    $s += $d[$i];
}
echo "<p>sum is " . $s . "</p>";
function foobar($string)
{
    echo "<p>" . $string . "</p>";
}
foobar("Hello, World!");
function Add_string($str1, $str2)
{
    $a = $str1 . " 영";
    $b = $str2 . " 일";
    return array($a, $b);
}
list($out1, $out2) = Add_string("삼", "이");
echo "<p>{$out1} <br> {$out2} </p>";
$a = 1;
$b = 2;
function ValSwap($amb1, $amb2)
{
    $tmp = $amb1;
    $amb1 = $amb2;
    $amb2 = $tmp;
Пример #10
0
<?php

$a = 1;
class MoneyBags
{
}
function abc(&$foobar)
{
    return $foobar;
}
$right = abc($a);
$wrong = abc(&$a);
$a = E_STRICT;
// Sniffer checks strings, and returns if no left paren afterwards
abc($x, $y, $z, &$a);
// nested function call
preg_replace($a, $b, trim(&$a));
foobar(3 & $a);
// LNUMBER + &
foobar($a & $b);
// variable + &
foobar($b[0] & $a);
// square bracket + &
foobar($a & $b);
// parenthesis + &
foobar(intval(3) & $b);
// function + &
foobar(&$b);
Пример #11
0
<?php

/**
 *@description 使用$GLOBALS---引用全局作用域中可用的全部变量
 */
//example 1
function test()
{
    $foo = 'local variable';
    echo '$foo in global scope: ' . $GLOBALS['foo'] . '<br />';
    echo '$foo in local scope: ' . $foo . '<br />';
}
$foo = php_uname();
test();
echo '<hr>';
//example 2
$conf['conf']['foo'] = 'this is foo';
$conf['conf']['bar'] = 'this is bar';
function foobar()
{
    global $conf;
    var_dump($conf);
    var_dump($GLOBALS['conf']);
}
foobar();
Пример #12
0
{
    usleep(500 * 1000);
}
function main($num)
{
    $cmd = file_get_contents("/proc/self/cmdline");
    $cmd = str_replace("", " ", $cmd);
    $start = microtime(true);
    echo "Starting {$num} procs\n";
    for ($i = 0; $i < $num; $i++) {
        $handles[] = proc_open($cmd . " {$i}", array(), $pipes);
    }
    while ($handles) {
        foreach ($handles as $i => $handle) {
            $status = proc_get_status($handle);
            if (!$status['running']) {
                proc_close($handle);
                unset($handles[$i]);
            }
        }
    }
    echo "Done {$num} procs\n";
    return microtime(true) - $start;
}
if (count($argv) > 1) {
    foobar($argv[1]);
} else {
    $x10 = main(10);
    $x200 = main(200);
    echo $x10 * 20 < $x200 ? "Failed since {$x10} * 20 < {$x200}" : "Passed", "\n";
}
Пример #13
0
 function Foo()
 {
     $this->foobar();
     foobar();
 }
$arr = [2 => 7, "foo" => "bar", "foobar" => NULL, "qux" => $obj, "bing" => ["bang"]];
function foobar()
{
    echo "called\n";
    return ['a'];
}
var_dump($nonexistent_variable ?? 3);
echo PHP_EOL;
var_dump($var ?? 3);
var_dump($var2 ?? 3);
echo PHP_EOL;
var_dump($obj->boo ?? 3);
var_dump($obj->bing ?? 3);
var_dump($arr["qux"]->boo ?? 3);
var_dump($arr["qux"]->bing ?? 3);
echo PHP_EOL;
var_dump($arr[2] ?? 3);
var_dump($arr["foo"] ?? 3);
var_dump($arr["foobar"] ?? 3);
var_dump($arr["qux"] ?? 3);
var_dump($arr["bing"][0] ?? 3);
var_dump($arr["bing"][1] ?? 3);
echo PHP_EOL;
var_dump(foobar()[0] ?? false);
echo PHP_EOL;
function f($x)
{
    printf("%s(%d)\n", __FUNCTION__, $x);
    return $x;
}
$a = f(null) ?? f(1) ?? f(2);
Пример #15
0
$env2 = new Environment();
function foobar($value)
{
    return Shared::value('foobar', function () use($value) {
        return $value;
    });
}
$env1->importFunction('foobar');
$env2->importFunction('foobar');
$env1->execute(function () {
    ob_implicit_flush(1);
    var_dump(foobar('x')->get());
});
$env2->execute(function () {
    ob_implicit_flush(1);
    var_dump(foobar('y')->get());
});
var_dump(Shared::reset('foobar'));
$env2->execute(function () {
    ob_implicit_flush(1);
    var_dump(foobar('y')->get());
});
?>
--EXPECTF--
string(1) "x"
string(1) "x"
object(php\util\SharedValue)#%d (1) {
  ["*value"]=>
  string(1) "x"
}
string(1) "y"
Пример #16
0
 static function c()
 {
     foobar();
 }
Пример #17
0
<?php

class foobar
{
    public function __destruct()
    {
        throw new Exception();
    }
    public function __call($m, $a)
    {
        return $this;
    }
}
function foobar()
{
    return new foobar();
}
try {
    foobar()->unknown();
} catch (Exception $e) {
    echo "__call via traditional factory should be caught\n";
}
 public function foobar($param1, $param2)
 {
     return foobar($param1, $param2) . ':' . self::$_instanceCounter;
 }
Пример #19
0
function redirect($target)
{
    $target = make_absolute($target);
    if ($debug || $stop_redirect) {
        global $login_id, $anon_ok;
        echo "debug or stop redirect... {$login_id} {$anon_ok} ";
        var_dump($target);
        var_dump($_SERVER);
        $s = trim(@$_SESSION['flash']);
        if ($s != "") {
            $body .= "<p>pending flash: \n";
            $body .= h($s);
            $body .= "</p>\n";
        }
        $body .= "<p>";
        $body .= mklink("(dbg=1: click here to finish redirect)", $target);
        $body .= "</p>\n";
        foobar();
        pfinish();
    }
    session_write_close();
    do_commits();
    ob_clean();
    header("Location: {$target}");
    exit;
}