Пример #1
0
function main()
{
    f1();
    f2();
    f3();
    f4();
    f5();
    f6();
    f7();
    f8();
}
Пример #2
0
{
    $arr = array(1, 2, 3);
    foreach ($arr as &$v1) {
        foreach ($arr as $v2) {
            return;
        }
    }
}
function f3()
{
    $arr = array(1, 2, 3);
    foreach ($arr as $v1) {
        foreach ($arr as &$v2) {
            return;
        }
    }
}
function f4()
{
    $arr = array(1, 2, 3);
    foreach ($arr as &$v1) {
        foreach ($arr as &$v2) {
            return;
        }
    }
}
f1();
f2();
f3();
f4();
echo "Done\n";
Пример #3
0
        var_dump($k, $v);
    }
}
function f5($x)
{
    switch ($x[0]) {
        case 0:
            var_dump($x[0]);
    }
}
function f6($x, $y, $z)
{
    if ($z) {
        goto my_clause;
    }
    if ($y) {
        var_dump($y);
    } else {
        if ($x[0]) {
            var_dump($x[0]);
            my_clause:
            var_dump($x);
        }
    }
}
f1(array(0, 0));
f2(array(10));
f3(array(10), false);
f4(array(array(1, 2, 3)));
f5(array(false, false));
f6(array(true), false, false);
Пример #4
0
function f3()
{
    f4();
    f5();
}
Пример #5
0
{
}
class C2 implements I1
{
}
class D2 extends C2 implements I2
{
}
function f4(I1 $p1)
{
    echo "Inside " . __METHOD__ . "\n";
    var_dump($p1);
}
//f4(123); // must implement interface I1, integer given
f4(new C2());
f4(new D2());
echo "--------------- test type hint callable ---------------------\n";
function hello()
{
    echo "Hello!\n";
}
function f5(callable $p1)
{
    echo "Inside " . __METHOD__ . "\n";
    var_dump($p1);
    $p1();
}
//f5(123); // must be callable, integer given
f5('hello');
echo "--------------- test type hint + by ref ---------------------\n";
function f6(C1 &$p1)
Пример #6
0
<?php

function f4(&$d)
{
    htmlspecialchars($d);
    ## doing nothing
}
echo 1;
f4($_GET['a']);
echo $_GET['a'];
Пример #7
0
echo 'f(10, 12) + g(15) = ' . (f(10, 12) + g(15)) . "\n";
echo 'f(10, 12) - g(15) = ' . (f(10, 12) - g(15)) . "\n";
echo 'f(10, 12) * g(15) = ' . f(10, 12) * g(15) . "\n";
echo 'f(10, 12) / g(15) = ' . f(10, 12) / g(15) . "\n";
function f1($a)
{
    echo "Inside f1\n";
    return $a;
}
function f2($a)
{
    echo "Inside f2\n";
    return $a;
}
function f3($a)
{
    echo "Inside f3\n";
    return $a;
}
function f4($a)
{
    echo "Inside f4\n";
    return $a;
}
$values = array(0, 1, 2, 3, 4, 5, 6);
var_dump($values);
$values[f1(4) - f2(2)] = $values[f3(3) * f4(2)];
var_dump($values);
$values = array(0, 1, 2, 3, 4, 5, 6);
$values[f1(1) + f2(2)] = $values[f3(6) / f4(3)];
var_dump($values);
Пример #8
0
        var_dump($x[0]);
    }
    var_dump($x[0]);
}
f2(array(0 => array()));
f2(array());
f2('');
f2($o);
f2(null);
function f3($x)
{
    foreach ($x['foo'] as $k => $v) {
        if ($v) {
            unset($x['foo'][$k]);
        }
    }
    var_dump($x);
}
f3(array('foo' => array(0, 1, 2, 3)));
function f4($x)
{
    var_dump($x[0][1]);
    unset($x[0][1]);
    var_dump($x[0][1]);
}
f4(array(array(1 => new stdClass())));
function f5($x)
{
    var_dump(md5($x[0]), $x[0]);
}
f5('foobar');
Пример #9
0
}
function f2($x)
{
    if ($x[0]) {
        var_dump(id($x), $x[0]);
    }
}
f2(null);
f2(array());
f2(array(10));
function f3($x)
{
    var_dump($x[0] . '/' . $x[1]);
    var_dump($x[0] . '/' . $x[1]);
}
f3(array('first', 'second'));
f3('AB');
function f4($x)
{
    $z = @id($x[0]);
    var_dump($z);
    var_dump($x[0]);
}
f4(array('e1', 'e2'));
function f5($x)
{
    if ($x[0][id($x[0]) - 1]) {
        var_dump($x);
    }
}
f5(array(0, 1, 2));
Пример #10
0
<?php

function f4()
{
    $i = 0;
    $foo = array('a' => 1, 'b' => 2, 'c' => 3, 'd' => 4, 'e' => 5, 'f' => 6);
    $bar = array();
    $a = 0;
    foreach ($foo as $key => &$val) {
        (yield null);
        echo "key={$key} val={$val}\n";
        if ($key == 'b' && $a == 0) {
            $a = 1;
            unset($foo['c']);
            $bar['b'] = 888;
            $foo['c'] = 333;
        }
        ++$i;
        if ($i >= 20) {
            break;
        }
    }
    var_dump($foo);
}
foreach (f4() as $_) {
}
Пример #11
0
function f5($v10)
{
    $v26 = array();
    array_push($v26, '<' . urldecode("%3F") . 'xml version="1.0"' . urldecode("%3F") . '>');
    array_push($v26, '<playlist>');
    for ($i = 0; $i < sizeof($v10); $i++) {
        array_push($v26, '<item>');
        foreach ($v10[$i] as $key => $v117) {
            $v42 = f4($v117);
            array_push($v26, '<' . $key . '>' . $v42 . '</' . $key . '>');
        }
        array_push($v26, '</item>');
    }
    array_push($v26, '</playlist>');
    header("Pragma: public", false);
    header("Expires: Thu, 19 Nov 1981 08:52:00 GMT", false);
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0", false);
    header("Cache-Control: no-store, no-cache, must-revalidate", false);
    header("Content-Type: text/xml");
    print implode("", $v26);
    exit;
}
Пример #12
0
function bar()
{
    $a = 1;
    f1($a, $a, $a);
    var_dump($a);
    $a = 1;
    f2($a, $a, $a);
    var_dump($a);
    $a = 1;
    f3($a, $a, $a);
    var_dump($a);
    $a = 1;
    f4($a, $a, $a);
    var_dump($a);
    $a = 1;
    f5($a, $a, $a);
    var_dump($a);
    $a = 1;
    f6($a, $a, $a);
    var_dump($a);
    $a = 1;
    f7($a, $a, $a);
    var_dump($a);
    $a = 1;
    f8($a, $a, $a);
    var_dump($a);
}
Пример #13
0
function f6(double $x = null)
{
    $y = (double) $x;
    var_dump($y);
    return $y;
}
var_dump(f1());
var_dump(f2());
var_dump(f3());
var_dump(f4());
var_dump(f5());
var_dump(f6());
var_dump(f1(null));
var_dump(f2(null));
var_dump(f3(null));
var_dump(f4(null));
var_dump(f5(null));
var_dump(f6(null));
function rf1($x)
{
    if ($x) {
        return 'f1';
    }
    return 0;
}
function rf2($x)
{
    if ($x) {
        return 'f2';
    }
    return 0;
Пример #14
0
$out_f4 = f4();
var_dump($out_f4);
// int(2)
$out_f4 = 10;
var_dump($out_f4);
// int(10)
$out_f4 = f4();
var_dump($out_f4);
// int(3)
$out_f4 =& f4();
var_dump($out_f4);
// int(4)
$out_f4 = 10;
var_dump($out_f4);
// int(10)
$out_f4 = f4();
var_dump($out_f4);
// int(5) [*]
function &f5()
{
    static $in_f5 = 0;
    $in_f5++;
    return $in_f5;
}
$out_f5 = f5();
var_dump($out_f5);
// int(1)
$out_f5 = f5();
var_dump($out_f5);
// int(2)
$out_f5 = 10;
Пример #15
0
function f15($v8)
{
    $v9 = array();
    for ($i = 0; $i < sizeof($v8); $i++) {
        $v65 = $v8[$i];
        if (strtolower(substr($v65, 0, 4)) == "file") {
            $v15 = explode("=", $v65);
            $v16 = explode("=", $v8[$i + 1]);
            $v17 = explode("=", $v8[$i + 2]);
            $v32 = array();
            $v32['filename'] = $v15[1];
            $v32['artist'] = "";
            $v32['album'] = "";
            $v32['title'] = $v16[1];
            $v32['track'] = "";
            $v32['comments'] = "";
            $v32['genre'] = "";
            $v32['seconds'] = $v17[1];
            $v32['filesize'] = "";
            $v32['bitrate'] = "";
            $v32['visual'] = "";
            $i++;
            $i++;
            $v9[sizeof($v9)] = $v32;
        }
    }
    f4($v9);
}
Пример #16
0
// 1 default followed by one non-default followed by 1 default; unusual, but permitted
function f3($p1 = 100, $p2, $p3 = "abc")
{
    $argList = func_get_args();
    echo "f3: # arguments passed is " . count($argList) . "\n";
    foreach ($argList as $k => $e) {
        echo "\targ[{$k}] = >{$e}<\n";
    }
    echo "\$p1: " . ($p1 == NULL ? "NULL" : $p1) . ", \$p2: " . ($p2 == NULL ? "NULL" : $p2) . ", \$p3: " . ($p3 == NULL ? "NULL" : $p3) . "\n";
}
f3();
f3(10);
f3(10, 20);
f3(10, 20, 30);
//*/
///*
// 1 non-default followed by two default; unusual, but permitted
function f4($p1, $p2 = 1.23, $p3 = "abc")
{
    $argList = func_get_args();
    echo "f4: # arguments passed is " . count($argList) . "\n";
    foreach ($argList as $k => $e) {
        echo "\targ[{$k}] = >{$e}<\n";
    }
    echo "\$p1: " . ($p1 == NULL ? "NULL" : $p1) . ", \$p2: " . ($p2 == NULL ? "NULL" : $p2) . ", \$p3: " . ($p3 == NULL ? "NULL" : $p3) . "\n";
}
f4();
f4(10);
f4(10, 20);
f4(10, 20, 30);
//*/
Пример #17
0
function f2($a, $b)
{
    print $a;
    print $b;
}
f2($HTTP_RAW_POST_DATA, $http_raw_post_data);
function f3($a, $b)
{
    echo $a;
    echo $b;
}
f3($_SERVER['DOCUMENT_ROOT'], $_SERVER['QUERY_STRING']);
function f4($a, $b)
{
    print $a;
    print $b;
}
f4($_SERVER['DOCUMENT_ROOT'], $_SERVER['QUERY_STRING']);
// Those are called with safe functions.
function f5($a, $b)
{
    strtolower($a);
    strtolower($b);
}
f5($_SERVER, $_SERVER);
function f6($a, $b)
{
    strtolower($a);
    strtolower($b);
}
f6($_SERVER['DOCUMENT_ROOT'], $_SERVER['QUERY_STRING']);