示例#1
0
function main()
{
    $x = new D1();
    var_dump($x->heh($x));
    $y = gen(1);
    var_dump($y->heh($y));
}
function yf()
{
    $x = (yield from gen(1));
    echo "x is {$x}\n";
    $y = (yield from gen(2));
    echo "y is {$y}\n";
    return yield from gen(42);
}
示例#3
0
文件: 2186.php 项目: badlamer/hhvm
function test()
{
    $x = 0;
    foreach (gen($x) as $y) {
        var_dump($y);
    }
    var_dump($x);
}
function gen($a = 0)
{
    (yield 1 + $a);
    if ($a < 1) {
        var_dump(yield from gen($a + 1));
    }
    (yield 3 + $a);
    return 5 + $a;
}
function gen($i = 0)
{
    if ($i < 1000) {
        yield from gen(++$i);
    } else {
        (yield $i);
        yield from from(++$i);
    }
}
示例#6
0
function genSess($seed)
{
    global $totalSessionsStd;
    $var = $seed % 10;
    echo 'Total activities in each session : ' . $var . '<br />';
    while ($var > 0) {
        $a = gen();
        //echo 'a : '.$a.'<br />';
        $var--;
    }
}
function gen($a = 0)
{
    (yield 1 + $a);
    if ($a < 1) {
        // TODO: HHVM currently does not support yield from (or yield) as
        // expressions. As such, this test had to be slightly modified.
        // The original line was:
        // var_dump(yield from gen($a + 1));
        $b = (yield from gen($a + 1));
        var_dump($b);
    }
    (yield 3 + $a);
    return 5 + $a;
}
示例#8
0
function main()
{
    pure_function_2(1, 2);
    fb_setprofile('profiler');
    pure_function_2(3, 4);
    srand(0xdeadbeef);
    try {
        test_exception();
    } catch (Exception $e) {
        //do nothing.
    }
    foreach (gen() as $x) {
    }
    fb_setprofile(null);
    pure_function_2(5, 6);
}
示例#9
0
文件: 2183.php 项目: jeremyadoux/hhvm
function main()
{
    $GLOBALS['cont'] = $c = gen();
    echo "iter 1\n";
    $c->next();
    echo "iter 2\n";
    $c->send(new Evil());
    $GLOBALS['gonext'] = true;
    echo "iter 3\n";
    $c->next();
    echo "iter 4\n";
    $c->send(null);
    echo "iter 5\n";
    $c->send(null);
    echo "Finished!\n";
}
示例#10
0
function genSess($seed)
{
    global $totalSessionsStd;
    $var = $seed % 10;
    $var = rand($var--, $var++);
    $a = "";
    $count = 0;
    while ($var > 0) {
        $b = gen();
        if (($var != 1 || $count != 0) && $a != "") {
            $a = $a . ';';
        }
        $a = $a . $b;
        $var--;
        $count++;
    }
    return $a;
}
示例#11
0
 function gen()
 {
     chdir("l");
     if (!file_exists($dir)) {
         chdir("../");
         $g = array('\'', '"', '\\', '\\;', '\\$', '\\>', '\\<');
         $b = array('', '', '', '', '', '', '');
         $GLOBALS["l1"] = str_replace($b, $g, $GLOBALS["l1"]);
         $GLOBALS["l2"] = str_replace($b, $g, $GLOBALS["l2"]);
         $dir = base64_encode(mt_rand(1, 2000000000));
         mkdir("l/" . $dir);
         chdir("l/" . $dir);
         $fcon = "<?php\n\terror_reporting(0);\n\t\$d = date('i');\n\t\$d = intval(\$d);\n\tif (\$d % 2 == 0) {\n\t\theader('Location: " . $GLOBALS["l1"] . "');\n\t}else{\n\t\theader('Location: " . $GLOBALS["l2"] . "');\n\t}\n" . '?>' . "";
         file_put_contents("index.php", $fcon);
         $fu = ServerURL . $dir;
         echo "<font face='arial'>\n<center>\n<div style='width:50%;'>\n<a href='http://www.reddit.com/r/FiftyFifty/submit?url=" . $fu . "'>Submit to Reddit</a><p />\n<input type='text' style='width:50%;text-align: center;' value='" . $fu . "'/>\n<p />\n</div>\n</center>\n</font>";
     } else {
         gen();
     }
 }
示例#12
0
文件: 660.php 项目: badlamer/hhvm
<?php

class A
{
    var $a;
    var $b;
}
function gen()
{
    $obj = new A();
    $obj2 = $obj;
    foreach ($obj2 as $k => &$value) {
        (yield null);
        $value = 'ok';
    }
    var_dump($obj);
    var_dump($obj2);
}
foreach (gen() as $_) {
}
示例#13
0
    echo "FINISH <br>";
}
foreach (nums() as $v) {
    //echo "VALUE: $v <br>";
}
/*********/
//возвращение значений
function gen()
{
    (yield 'a');
    (yield 'b');
    (yield 'name' => 'John');
    (yield 'd');
    //yield 10 => 'Hello';
    (yield 'e');
}
foreach (gen() as $k => $v) {
    echo "{$k} : {$v}<br>";
}
/*********/
//приём значений
function echoLogger()
{
    while (true) {
        echo 'Log: ' . yield . '<br>';
    }
}
//сенд отправляет значение на место йелд
$logger = echoLogger();
$logger->send('ЮПА!');
$logger->send('ЮПА-СТАЙЛ!');
<?php

function gen()
{
    yield;
    return;
}
function gen2()
{
    yield;
    return null;
}
function gen3()
{
    return;
    yield;
}
function gen4()
{
    return;
    yield;
}
var_dump(gen());
var_dump(gen2());
var_dump(gen3());
var_dump(gen4());
示例#15
0
<?php

function gen()
{
    $a = 1;
    (yield $a);
}
@eval('abc');
$values = gen();
$values->next();
?>
===DONE===
示例#16
0
文件: csrf.php 项目: hynial/PHP
<?php

function gen($len = 5)
{
    $token = '';
    while ($len--) {
        $choose = rand(0, 2);
        if ($choose == 0) {
            $token .= chr(rand(ord('A'), ord('Z')));
        } else {
            if ($choose == 1) {
                $token .= chr(rand(ord('a'), ord('z')));
            } else {
                $token .= chr(rand(ord('0'), ord('9')));
            }
        }
    }
    return $token;
}
echo gen(5);
echo '\\n';
示例#17
0
文件: 2176.php 项目: badlamer/hhvm
{
}
class ReflectedException extends Exception
{
}
function throwYieldedException()
{
    throw new YieldedException();
}
function gen()
{
    try {
        $a = (yield throwYieldedException());
        echo 'Gen got ' . $a;
    } catch (YieldedException $e) {
        var_dump('Got yieldedException, re-raising.');
        throw $e;
    } catch (ReflectedException $e) {
        var_dump('Got Reflected Exception');
    }
}
try {
    $g = gen();
    $g->next();
} catch (YieldedException $e) {
    try {
        $g->raise(new ReflectedException());
    } catch (Exception $e) {
        var_dump($e->getMessage());
    }
}
{
    //	$chars="qazxswedcvfrtgbnhyujmkiolp1234567890QAZXSWEDCVFRTGBNHYUJMKIOLP";
    $chars = "1234567890";
    $max = 6;
    $size = strlen($chars) - 1;
    $confirm_code = null;
    while ($max--) {
        $confirm_code .= $chars[rand(0, $size)];
    }
    return $confirm_code;
}
if (!empty($phone) && !empty($key)) {
    // Сохраняем код подтверждения в кэш
    $cache = $modx->cacheManager;
    $cache_key = '/confirmphone/';
    $confirmation_code = gen();
    $cache->set($cache_key . $key, $confirmation_code, 600);
    $modx->log(xPDO::LOG_LEVEL_ERROR, 'Save_code: ' . $cache_key . $key);
    if (!in_array(trim(preg_replace('/[0-9]/', '#', $phone)), array('(###) ###-####', '##########'))) {
        return '';
    }
    $phone = str_replace(" ", "", $phone);
    $phone = str_replace("(", "", $phone);
    $phone = str_replace(")", "", $phone);
    $phone = str_replace("-", "", $phone);
    $target = '+7' . $phone;
    $sender = '7152';
    $result = $sms->post_message($confirmation_code, $target, $sender);
    $out = array();
    $out['session_id'] = $key;
    $out['phone'] = $phone;
    foreach (range(0, 2 << $levels) as $v) {
        (yield $v);
    }
}
function gen($gen, $level)
{
    if ($level % 2) {
        (yield $gen->current());
    }
    yield from $gen;
}
foreach (range(0, 6) as $levels) {
    print "{$levels} level" . ($levels == 1 ? "" : "s") . "\n\n";
    $all = array();
    $all[] = $gens[0][0] = from($levels);
    for ($level = 1; $level < $levels; $level++) {
        for ($i = 0; $i < 1 << $level; $i++) {
            $all[] = $gens[$level][$i] = gen($gens[$level - 1][$i >> 1], $level);
        }
    }
    while (1) {
        foreach ($all as $gen) {
            var_dump($gen->current());
            $gen->next();
            if (!$gen->valid()) {
                break 2;
            }
        }
    }
    print "\n\n";
}
示例#20
0
文件: 2177.php 项目: badlamer/hhvm
<?php

function makeClosureCont()
{
    return function () {
        static $x = 0;
        (yield $x++);
        (yield $x++);
    };
}
function gen()
{
    static $x = 0;
    (yield $x++);
    (yield $x++);
}
$cc = makeClosureCont();
foreach ($cc() as $v) {
    var_dump($v);
}
$cc1 = makeClosureCont();
foreach ($cc1() as $v) {
    var_dump($v);
}
foreach (gen() as $v) {
    var_dump($v);
}
foreach (gen() as $v) {
    var_dump($v);
}
<?php

class Foo
{
    public function __construct()
    {
    }
}
function gen()
{
    $x = new Foo(yield);
}
gen()->rewind();
?>
===DONE===
<?php

function gen()
{
    (yield "foo" => 0);
    (yield 1 => 1);
    (yield 2.5 => 2);
    (yield null => 3);
    (yield [] => 4);
    (yield new stdClass() => 5);
}
var_dump(iterator_to_array(gen()));
<?php

function gen()
{
    throw new Exception("foo");
    yield;
    // force generator
}
foreach (gen() as $value) {
}
示例#24
0
function function_with_3_args()
{
    $gen = gen();
    $gen->rewind();
}
示例#25
0
--TEST--
Yield can be used during a method call
--FILE--
<?php 
class A
{
    public function b($c)
    {
        echo $c, "\n";
    }
}
function gen()
{
    $a = new A();
    $a->b(yield);
}
$gen = gen();
$gen->send('foo');
// test resource cleanup
$gen = gen();
$gen->rewind();
unset($gen);
?>
--EXPECT--
foo
示例#26
0
function genSess($seed)
{
    global $totalSessionsStd;
    $var = $seed % 10;
    if ($var == 0) {
        $var = 3;
    }
    $var = rand($var--, $var++);
    //echo 'Total Activity in each session : '.$var.'<br />';
    $a = "";
    $count = 0;
    while ($var > 0) {
        $b = gen($seed);
        if (($var != 1 || $count != 0) && $a != "") {
            $a = $a . ',';
        }
        $a = $a . $b;
        $var--;
        $count++;
    }
    return $a;
}
--TEST--
The result of a by-ref function call can be yielded just fine
--FILE--
<?php 
function &nop(&$var)
{
    return $var;
}
function &gen(&$var)
{
    (yield nop($var));
}
$var = "foo";
$gen = gen($var);
foreach ($gen as &$varRef) {
    $varRef = "bar";
}
var_dump($var);
?>
--EXPECT--
string(3) "bar"
示例#28
0
文件: 2166.php 项目: badlamer/hhvm
<?php

function get()
{
    return true;
}
if (get()) {
    function gen($i)
    {
        (yield $i);
        (yield $i + 1);
    }
} else {
    function gen($i)
    {
        (yield $i + 1);
        (yield $i + 2);
    }
}
foreach (gen(3) as $x) {
    var_dump($x);
}
示例#29
0
<?php

function &gen(array &$array)
{
    (yield $array[0]);
}
$array = [1, 2, 3];
$gen = gen($array);
foreach ($gen as &$val) {
    $val *= -1;
}
var_dump($array);
<?php

function gen()
{
    $bar = ["some complex var"];
    ${"f" . "oo"} = "force symtable usage";
    var_dump($bar);
    yield;
}
gen()->valid();