本文整理汇总了PHP中gen函数的典型用法代码示例。如果您正苦于以下问题:PHP gen函数的具体用法?PHP gen怎么用?PHP gen使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了gen函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: main
function main()
{
$x = new D1();
var_dump($x->heh($x));
$y = gen(1);
var_dump($y->heh($y));
}
开发者ID:badlamer,项目名称:hhvm,代码行数:7,代码来源:method_resolution_001.php
示例2: yf
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);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:8,代码来源:yield_from_return_values.php
示例3: test
function test()
{
$x = 0;
foreach (gen($x) as $y) {
var_dump($y);
}
var_dump($x);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:8,代码来源:2186.php
示例4: gen
function gen($a = 0)
{
(yield 1 + $a);
if ($a < 1) {
var_dump(yield from gen($a + 1));
}
(yield 3 + $a);
return 5 + $a;
}
开发者ID:gleamingthecube,项目名称:php,代码行数:9,代码来源:Zend_tests_generators_multiple_yield_from_on_same_generator.php
示例5: gen
function gen($i = 0)
{
if ($i < 1000) {
yield from gen(++$i);
} else {
(yield $i);
yield from from(++$i);
}
}
开发者ID:badlamer,项目名称:hhvm,代码行数:9,代码来源:yield_from_deep_recursion.php
示例6: genSess
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--;
}
}
开发者ID:meghaukkali,项目名称:SPAS,代码行数:11,代码来源:practise.php
示例7: gen
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;
}
开发者ID:badlamer,项目名称:hhvm,代码行数:14,代码来源:yield_from_advance_inner_generator.php
示例8: main
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);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:16,代码来源:Setprofile.php
示例9: main
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";
}
开发者ID:jeremyadoux,项目名称:hhvm,代码行数:16,代码来源:2183.php
示例10: genSess
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;
}
开发者ID:Param999,项目名称:SPAS,代码行数:18,代码来源:addNewActStd.php
示例11: gen
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();
}
}
开发者ID:Degstu,项目名称:Degstu-5050,代码行数:20,代码来源:process.php
示例12: gen
<?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 $_) {
}
开发者ID:badlamer,项目名称:hhvm,代码行数:20,代码来源:660.php
示例13: foreach
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('ЮПА-СТАЙЛ!');
开发者ID:kapsilon,项目名称:Specialist,代码行数:31,代码来源:3a.php
示例14: gen
<?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());
开发者ID:gleamingthecube,项目名称:php,代码行数:26,代码来源:Zend_tests_generators_generator_return_without_value.php
示例15: gen
<?php
function gen()
{
$a = 1;
(yield $a);
}
@eval('abc');
$values = gen();
$values->next();
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:12,代码来源:bug67497.php
示例16: gen
<?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';
开发者ID:hynial,项目名称:PHP,代码行数:21,代码来源:csrf.php
示例17: throwYieldedException
{
}
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());
}
}
开发者ID:badlamer,项目名称:hhvm,代码行数:31,代码来源:2176.php
示例18: strlen
{
// $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;
开发者ID:antoncom,项目名称:messenger,代码行数:31,代码来源:send_phone_confirmation.php
示例19: foreach
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";
}
开发者ID:gleamingthecube,项目名称:php,代码行数:31,代码来源:Zend_tests_generators_yield_from_multi_tree.php
示例20: makeClosureCont
<?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);
}
开发者ID:badlamer,项目名称:hhvm,代码行数:30,代码来源:2177.php
注:本文中的gen函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论