コード例 #1
0
ファイル: intrinsics_unset.php プロジェクト: jeremyadoux/hhvm
    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)
{
    var_dump(isset($p1, $p2));
    unset($p1, $p2);
    // unsets local "version" in current scope
    var_dump(isset($p1, $p2));
}
$v1 = 10;
$v2 = 20;
g3($v1, $v2);
var_dump(isset($v1));
// still set
コード例 #2
0
ファイル: g2_import_task.php プロジェクト: viosca/gallery3
 static function import($task)
 {
     $start = microtime(true);
     g2_import::init();
     $stats = $task->get("stats");
     $done = $task->get("done");
     $total = $task->get("total");
     $completed = $task->get("completed");
     $mode = $task->get("mode");
     $queue = $task->get("queue");
     if (!isset($mode)) {
         $stats = g2_import::stats();
         $stats["items"] = $stats["photos"] + $stats["movies"];
         unset($stats["photos"]);
         unset($stats["movies"]);
         $stats["highlights"] = $stats["albums"];
         $task->set("stats", $stats);
         $task->set("total", $total = array_sum(array_values($stats)));
         $completed = 0;
         $mode = 0;
         $done = array();
         foreach (array_keys($stats) as $key) {
             $done[$key] = 0;
         }
         $task->set("done", $done);
         $root_g2_id = g2(GalleryCoreApi::getDefaultAlbumId());
         $root = ORM::factory("g2_map")->where("g2_id", "=", $root_g2_id)->find();
         if (!$root->loaded()) {
             $root->g2_id = $root_g2_id;
             $root->g3_id = 1;
             $root->save();
         }
     }
     $modes = array("groups", "users", "albums", "items", "comments", "tags", "highlights", "done");
     while (!$task->done && microtime(true) - $start < 1.5) {
         if ($done[$modes[$mode]] == $stats[$modes[$mode]]) {
             // Nothing left to do for this mode.  Advance.
             $mode++;
             $task->set("last_id", 0);
             $queue = array();
             // Start the loop from the beginning again.  This way if we get to a mode that requires no
             // actions (eg, if the G2 comments module isn't installed) we won't try to do any comments
             // queries.. in the next iteration we'll just skip over that mode.
             if ($modes[$mode] != "done") {
                 continue;
             }
         }
         switch ($modes[$mode]) {
             case "groups":
                 if (empty($queue)) {
                     $task->set("queue", $queue = array_keys(g2(GalleryCoreApi::fetchGroupNames())));
                 }
                 $log_message = g2_import::import_group($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing groups (%count of %total)", array("count" => $done["groups"] + 1, "total" => $stats["groups"]));
                 break;
             case "users":
                 if (empty($queue)) {
                     $task->set("queue", $queue = array_keys(g2(GalleryCoreApi::fetchUsersForGroup(GROUP_EVERYBODY))));
                 }
                 $log_message = g2_import::import_user($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing users (%count of %total)", array("count" => $done["users"] + 1, "total" => $stats["users"]));
                 break;
             case "albums":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree()));
                 }
                 $log_message = g2_import::import_album($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing albums (%count of %total)", array("count" => $done["albums"] + 1, "total" => $stats["albums"]));
                 break;
             case "items":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_item_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_item($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing photos (%count of %total)", array("count" => $done["items"] + 1, "total" => $stats["items"]));
                 break;
             case "comments":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_comment_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_comment($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing comments (%count of %total)", array("count" => $done["comments"] + 1, "total" => $stats["comments"]));
                 break;
             case "tags":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_tag_item_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_tags_for_item($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing tags (%count of %total)", array("count" => $done["tags"] + 1, "total" => $stats["tags"]));
                 break;
             case "highlights":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree()));
                 }
                 $log_message = g2_import::set_album_highlight($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Album highlights (%count of %total)", array("count" => $done["tags"] + 1, "total" => $stats["albums"]));
                 break;
             case "done":
                 $task->status = t("Import complete");
                 $task->done = true;
                 $task->state = "success";
                 break;
         }
         if (!$task->done) {
             $done[$modes[$mode]]++;
             $completed++;
         }
     }
     $task->percent_complete = 100 * ($completed / $total);
     $task->set("completed", $completed);
     $task->set("mode", $mode);
     $task->set("queue", $queue);
     $task->set("done", $done);
 }
コード例 #3
0
ファイル: g2_import.php プロジェクト: hiwilson/gallery3
 /**
  * Get a set of comment ids from Gallery 2 greater than $min_id.  We use this to get the
  * next chunk of comments to import.
  */
 static function get_tag_item_ids($min_id)
 {
     global $gallery;
     $ids = array();
     $results = g2($gallery->search("SELECT DISTINCT([TagItemMap::itemId]) FROM [TagItemMap] " . "WHERE [TagItemMap::itemId] > ?", array($min_id), array("limit" => array("count" => 100))));
     while ($result = $results->nextResult()) {
         $ids[] = $result[0];
     }
     return $ids;
 }
コード例 #4
0
ファイル: byrefs.php プロジェクト: badlamer/hhvm
    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
}
$b =& g2();
// make $b an alias to the dynamic program location formerly aliased by local variable $t
var_dump($b);
//*/
コード例 #5
0
unset($a);
// remove only alias from point, so destructor runs
echo "Done\n";
//*/
///*
echo "----------------- byRef returning of handle types ----------------------\n";
function &g2()
{
    $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 as though using $a =& $b
    // as $b goes away, remove its alias
}
$a = g2();
echo "After '\$a = f2()', \$a is {$a}\n";
unset($a);
// remove only alias from point, so destructor runs
echo "Done\n";
//*/
echo "----------------- unsetting properties ----------------------\n";
class C
{
    public $prop1;
    public $prop2;
    public function __destruct()
    {
        echo "\nInside " . __METHOD__ . "\n\n";
    }
}
コード例 #6
0
ファイル: gcode.php プロジェクト: samw3/phfab
function arc($x, $y, $x1, $y1, $x2, $y2, $z)
{
    g0(_, _, SAFE_Z);
    g0($x1, $y1, _);
    if (!is_array($z)) {
        $z = array($z);
    }
    $g2 = true;
    foreach ($z as $zz) {
        g1(_, _, $zz);
        if ($g2) {
            g2($x2, $y2, _, $x - $x1, $y - $y1, _);
        } else {
            g3($x1, $y1, _, $x - $x2, $y - $y2, _);
        }
        $g2 = !$g2;
    }
    g0(_, _, SAFE_Z);
}
コード例 #7
0
ファイル: g2_import.php プロジェクト: HarriLu/gallery3
 /**
  * Get a set of group ids from Gallery 2 greater than $min_id.  We use this to get the
  * next chunk of groups to import.
  */
 static function get_group_ids($min_id)
 {
     global $gallery;
     $ids = array();
     $results = g2($gallery->search("SELECT [GalleryGroup::id] " . "FROM [GalleryGroup] " . "WHERE [GalleryGroup::id] > ? " . "ORDER BY [GalleryGroup::id] ASC", array($min_id), array("limit" => array("count" => 100))));
     while ($result = $results->nextResult()) {
         $ids[] = $result[0];
     }
     return $ids;
 }
コード例 #8
0
ファイル: g2_import_task.php プロジェクト: JasonWiki/docs
 static function import($task)
 {
     g2_import::lower_error_reporting();
     $start = microtime(true);
     g2_import::init();
     $stats = $task->get("stats");
     $done = $task->get("done");
     $total = $task->get("total");
     $completed = $task->get("completed");
     $mode = $task->get("mode");
     $queue = $task->get("queue");
     if (!isset($mode)) {
         $stats = g2_import::g2_stats();
         $stats["items"] = $stats["photos"] + $stats["movies"];
         unset($stats["photos"]);
         unset($stats["movies"]);
         $stats["highlights"] = $stats["albums"];
         $task->set("stats", $stats);
         $task->set("total", $total = array_sum(array_values($stats)));
         $completed = 0;
         $mode = 0;
         $done = array();
         foreach (array_keys($stats) as $key) {
             $done[$key] = 0;
         }
         $task->set("done", $done);
         // Ensure G2 ACLs are compacted to speed up import.
         g2(GalleryCoreApi::compactAccessLists());
     }
     $modes = array("groups", "users", "albums", "items", "comments", "tags", "highlights", "done");
     while (!$task->done && microtime(true) - $start < 1.5) {
         if ($done[$modes[$mode]] == $stats[$modes[$mode]]) {
             // Nothing left to do for this mode.  Advance.
             $mode++;
             $task->set("last_id", 0);
             $queue = array();
             // Start the loop from the beginning again.  This way if we get to a mode that requires no
             // actions (eg, if the G2 comments module isn't installed) we won't try to do any comments
             // queries.. in the next iteration we'll just skip over that mode.
             if ($modes[$mode] != "done") {
                 continue;
             }
         }
         switch ($modes[$mode]) {
             case "groups":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_group_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_group($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing groups (%count of %total)", array("count" => $done["groups"] + 1, "total" => $stats["groups"]));
                 break;
             case "users":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_user_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_user($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing users (%count of %total)", array("count" => $done["users"] + 1, "total" => $stats["users"]));
                 break;
             case "albums":
                 if (empty($queue)) {
                     $g2_root_id = g2(GalleryCoreApi::getDefaultAlbumId());
                     $tree = g2(GalleryCoreApi::fetchAlbumTree());
                     $task->set("queue", $queue = array($g2_root_id => $tree));
                     // Update the root album to reflect the Gallery2 root album.
                     $root_album = item::root();
                     g2_import::set_album_values($root_album, g2(GalleryCoreApi::loadEntitiesById($g2_root_id)));
                     $root_album->save();
                 }
                 $log_message = g2_import::import_album($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing albums (%count of %total)", array("count" => $done["albums"] + 1, "total" => $stats["albums"]));
                 break;
             case "items":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_item_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_item($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing photos (%count of %total)", array("count" => $done["items"] + 1, "total" => $stats["items"]));
                 break;
             case "comments":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_comment_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_comment($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing comments (%count of %total)", array("count" => $done["comments"] + 1, "total" => $stats["comments"]));
                 break;
             case "tags":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2_import::get_tag_item_ids($task->get("last_id", 0)));
                     $task->set("last_id", end($queue));
                 }
                 $log_message = g2_import::import_tags_for_item($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Importing tags (%count of %total)", array("count" => $done["tags"] + 1, "total" => $stats["tags"]));
                 break;
             case "highlights":
                 if (empty($queue)) {
                     $task->set("queue", $queue = g2(GalleryCoreApi::fetchAlbumTree()));
                 }
                 $log_message = g2_import::set_album_highlight($queue);
                 if ($log_message) {
                     $task->log($log_message);
                 }
                 $task->status = t("Album highlights (%count of %total)", array("count" => $done["highlights"] + 1, "total" => $stats["highlights"]));
                 break;
             case "done":
                 $task->status = t("Import complete");
                 $task->done = true;
                 $task->state = "success";
                 break;
         }
         if (!$task->done) {
             $done[$modes[$mode]]++;
             $completed++;
         }
     }
     $task->percent_complete = 100 * ($completed / $total);
     $task->set("completed", $completed);
     $task->set("mode", $mode);
     $task->set("queue", $queue);
     $task->set("done", $done);
     g2_import::restore_error_reporting();
 }
コード例 #9
0
<?php

function g1()
{
    (yield 2);
    (yield 3);
    return 42;
}
function g2()
{
    (yield 1);
    $g1result = (yield from g1());
    (yield 4);
    return $g1result;
}
$g = g2();
foreach ($g as $yielded) {
    var_dump($yielded);
}
var_dump($g->getReturn());
コード例 #10
0
ファイル: 468.php プロジェクト: badlamer/hhvm
<?php

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