예제 #1
0
function g2()
{
    (yield 1);
    $g1result = (yield from g1());
    (yield 4);
    return $g1result;
}
예제 #2
0
var_dump(isset($x1->m));
$x2 = new X2();
var_dump(isset($x2->m));
unset($x2->m);
var_dump(isset($x2->m));
echo "---------- unsetting inside a function (global) ------------\n";
$gl = 100;
function g1()
{
    global $gl;
    var_dump(isset($gl));
    unset($gl);
    // unsets local "version" in current scope
    var_dump(isset($gl));
}
g1();
var_dump(isset($gl));
// still set
echo "---------- unsetting inside a function (\$GLOBALS) ------------\n";
function g2()
{
    var_dump(isset($GLOBALS['gl']));
    unset($GLOBALS['gl']);
    // unsets global "version"
    var_dump(isset($GLOBALS['gl']));
}
g2();
var_dump(isset($gl));
// no longer set
echo "---------- unsetting inside a function (pass-by-ref) ------------\n";
function g3($p1, &$p2)
    echo "\tInside function " . __FUNCTION__ . ", \$b is {$b}\n";
    $b->move(4, 6);
    // moving $b also moves $a
    echo "After '\$b->move(4, 6)', \$b is {$b}\n";
    $b = new Point(5, 7);
    // removes second alias from first point;
    // then create first alias to second new point
    // changing $b also changes $a as well, so $a's alias
    // is also removed, alowing the destructor run
    echo "After 'new Point(5, 7)', \$b is {$b}\n";
}
// $b goes away, remove its alias from new point
$a = new Point(1, 3);
// create first new point, and make $a an alias to it
echo "After '\$a = new Point(1, 3)', \$a is {$a}\n";
g1($a);
// $a is changed via change to $b
echo "After 'g1(\$a)', \$a is {$a}\n";
unset($a);
// remove only alias from point, so destructor runs
echo "Done\n";
//*/
///*
echo "----------------- value returning of handle types ----------------------\n";
function f2()
{
    $b = new Point(5, 7);
    // create first new point, and make $b an alias to it
    echo "After 'new Point(5, 7)', \$b is {$b}\n";
    return $b;
    // return a temporary copy, which is a new alias
예제 #4
0
파일: byrefs.php 프로젝트: badlamer/hhvm
//*/
///*
// return byRef
function &g1(&$p)
{
    echo '$p ' . (isset($p) ? "is set\n" : "is not set\n");
    echo "g1 In:  \$p: {$p}\n";
    $p = 200;
    // actual argument's value changed
    echo "g1 Out: \$p: {$p}\n\n";
    return $p;
    // return by reference (can't use & here)
}
$a = 10;
var_dump($a);
$b =& g1($a);
// change $a from 10 to 200; make $b an alias to $a
var_dump($a);
var_dump($b);
$b = -12;
// change $a/$b
var_dump($a);
var_dump($b);
//*/
///*
function &g2()
{
    echo "g2 In:\n";
    $t = "local";
    return $t;
    // return byRef
예제 #5
0
파일: index.php 프로젝트: 4u4v/think
<?php

// +----------------------------------------------------------------------
// | TOPThink [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2011 http://topthink.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <*****@*****.**>
// +----------------------------------------------------------------------
// $Id$
g1('1');
define('APP_PATH', dirname(__DIR__) . '/application/');
require dirname(__DIR__) . '/thinkphp/start.php';
echo '<br/>run :' . g1('1', '2', 6) . ' | mem:' . g1('1', '2', 'm') . 'kb';
dump(get_included_files());
function G1($start, $end = '', $dec = 4)
{
    static $_info = array();
    static $_mem = array();
    if (is_float($end)) {
        // 记录时间
        $_info[$start] = $end;
    } elseif (!empty($end)) {
        // 统计时间和内存使用
        if (!isset($_info[$end])) {
            $_info[$end] = microtime(TRUE);
        }
        if ($dec == 'm') {
            if (!isset($_mem[$end])) {
예제 #6
0
파일: gcode.php 프로젝트: samw3/phfab
function pocket($x1, $y1, $x2, $y2, $z)
{
    if ($x2 < $x1) {
        $t = $x1;
        $x1 = $x2;
        $x2 = $t;
    }
    if ($y2 < $y1) {
        $t = $y1;
        $y1 = $y2;
        $y2 = $t;
    }
    g0(_, _, SAFE_Z);
    if (!is_array($z)) {
        $z = array($z);
    }
    foreach ($z as $zz) {
        g0($x1, $y1, _);
        g1(_, _, $zz);
        $dx = $x2 - $x1;
        $dy = $y2 - $y1;
        $q = min($dx, $dy);
        $x = $x1;
        $y = $y1;
        while ($q >= 0) {
            g1($x + $dx, _, _);
            g1(_, $y + $dy, _);
            g1($x, _, _);
            g1(_, $y, _);
            $x += R;
            $y += R;
            $dx -= 2.0 * R;
            $dy -= 2.0 * R;
            $q -= 2.0 * R;
        }
    }
    g0(_, _, SAFE_Z);
}
예제 #7
0
파일: 466.php 프로젝트: badlamer/hhvm
<?php

function g1()
{
    $arr = array(0, 1, 2, 3);
    $b = true;
    foreach ($arr as &$v) {
        (yield null);
        echo "val={$v}\n";
        if ($b && $v == 1) {
            $b = false;
            $arr = array(4, 5, 6, 7);
        }
    }
}
foreach (g1() as $_) {
}