Ejemplo n.º 1
0
    $x = 10;
    // this is a local variable
    echo "inside testScope " . $x;
    echo "<BR>";
    global $x;
    // accessing global $x now!
    echo "inside testScope " . $x;
    echo "<BR>";
    $x = 1000;
    return 3.14;
}
// GLOBAL VARIABLES
$x = 100;
echo $x;
echo "<BR>";
$y = testScope();
echo "x is " . $x;
echo "<BR>";
echo "y is " . $y;
echo "<BR>";
echo "<hr><br>";
// OBJECTS
class Test
{
    const A_BIG_NUMBER = 11111;
    private $name;
    static $i = 0;
    function __construct($name)
    {
        $this->name = $name;
        self::$i += 1;
Ejemplo n.º 2
0
    <?php 
$arr = array('id:10' => 'モリタ', 'id:11' => '高木');
foreach ($arr as $value) {
    print "Value: {$value}<br>";
}
?>
    <?php 
function testScope()
{
    require_once 'func.php';
    $area = getArea(20, 14);
    print $scope;
    print '四角形の面積' . $area;
    return $scope;
}
print testScope();
print $scope;
//Notice: Undefined variable: scope in /Users/No51/Desktop/Git/php/hello.php on line 29
?>

    <?php 
require_once 'test.php';
$obj = new Test();
$obj->calculate(5, 2);
print "プロパティの値は{$obj->number}です";
?>


    <!-- $$a = 'word!';
      ?>
    <?php 
Ejemplo n.º 3
0
<?php

/**
 * test scope
 */
function testScope()
{
    $abc = true;
    if ($abc) {
        $aaa = "123";
    }
    echo $aaa;
}
// output 123
// php是函数作用域,非块级作用域
testScope();