コード例 #1
0
ファイル: func6.php プロジェクト: denson7/phpstudy
function test1($i)
{
    echo $i, '<br/>';
    //1
    ++$i;
    if ($i <= 4) {
        test1($i);
        //test1(2)
        /*
        echo $i,'<br/>';//2
        		++$i;
        		if($i<=10){
        			test1($i);//test1(3)
        				echo $i,'<br/>';//3
        				++$i;
        				if($i<=4){
        					test1($i);//test1(4)
        						echo $i,'<br/>';//4
        						++$i;
        						if($i<=4){
        							test1($i);
        						}
        				}
        		}
        */
    }
}
コード例 #2
0
 public function run()
 {
     $r = 0;
     for ($i = 0; $i < self::DEFAULT_ITERATIONS; $i++) {
         $r += test1() + test2(1, 2, 3) + self::test1() + self::test2(1, 2, 3);
     }
 }
    function content_5236ae0304b8c2_40162505($_smarty_tpl)
    {
        ?>
<h1>自定义函数yu 以block 方式显示</h1>
<?php 
        $_smarty_tpl->smarty->_tag_stack[] = array('yu2', array('times' => "5", 'size' => "5", 'color' => "blue"));
        $_block_repeat = true;
        echo test2(array('times' => "5", 'size' => "5", 'color' => "blue"), null, $_smarty_tpl, $_block_repeat);
        while ($_block_repeat) {
            ob_start();
            ?>
hello world<?php 
            $_block_content = ob_get_clean();
            $_block_repeat = false;
            echo test2(array('times' => "5", 'size' => "5", 'color' => "blue"), $_block_content, $_smarty_tpl, $_block_repeat);
        }
        array_pop($_smarty_tpl->smarty->_tag_stack);
        ?>

<h1>自定义函数yu 以function 方式显示</h1>
<?php 
        echo test1(array('times' => "5", 'size' => "5", 'content' => "hello 栩坚", 'color' => "red"), $_smarty_tpl);
        ?>


<?php 
    }
コード例 #4
0
ファイル: 1195.php プロジェクト: badlamer/hhvm
function test($test)
{
    test1();
    TeSt1();
    $test();
    $test = strtolower($test);
    $test(1, 2, 3);
}
コード例 #5
0
ファイル: file_path.php プロジェクト: zhangpanfei/test
function test1($path = '', $lv = 0)
{
    file_exists($path) or die($path . ' is not find');
    $head = opendir($path) or die('open the dir is error');
    while (false !== ($file = readdir($head))) {
        $sub_dir = $path . '\\' . $file;
        if ($file == '.' || $file == '..') {
            continue;
        } else {
            if (is_dir($sub_dir)) {
                echo str_repeat('-', $lv) . $file . "\n";
                test1($sub_dir, $lv + 1);
            } else {
                echo str_repeat('-', $lv) . $file . "\n";
            }
        }
    }
}
コード例 #6
0
ファイル: func4.php プロジェクト: denson7/phpstudy
//5
echo '<hr/>';
$j = 10;
echo $i, '<br/>';
//10
unset($i);
//
var_dump($i);
//NULL
echo $j, '<br/>';
function test1(&$i)
{
    $i = 15;
}
$i = 2;
test1($i);
var_dump($i);
//15
echo '<hr/>';
/*
Fatal error: Only variables can be passed by reference in
F:\psd1507\study\PHPCORE\day08\demo\func4.php on line 50
*/
// test1(3);
$filename = '1.txt.jpeg';
/*
Strict Standards: Only variables should be passed by reference in F:\psd1507\study\PHPCORE\day08\demo\func4.php on line 58
jpeg
*/
$arr = explode('.', $filename);
echo end($arr);
コード例 #7
0
ファイル: array_unset_add.php プロジェクト: dw4dev/Phalanger
[file]
<?php 
// test1
echo "test1 (PassedByCopy):\n";
function test1($x)
{
    $x[] = 4;
    var_dump($x);
    return $x;
}
$x = array();
$x[0] = 1;
$x[1] = 2;
$x[2] = 3;
unset($x[2]);
$x = test1($x);
$x[] = 5;
var_dump($x);
// test2
echo "\n\ntest2 (ReturnedByCopy):\n";
function test2()
{
    $x = array(1, 2, 3);
    unset($x[2]);
    var_dump($x);
    return $x;
}
$x = test2($x);
$x[] = 4;
var_dump($x);
// test3
コード例 #8
0
ファイル: foreach.php プロジェクト: rex786/php2js
$favorites = array('favcolor' => 'red', 'favmovie' => 'shawshank', 'favsong' => 'Yellow submarine');
function test1($favorites)
{
    $buf = '';
    foreach ($favorites as $fav) {
        $buf .= $fav;
    }
    echo 'Test foreach($arr as $val)' . "<br>\n";
    echo 'result: ' . ($buf === 'redshawshankYellow submarine' ? 'pass' : 'fail') . "<br><br>\n\n";
}
function test2($favorites)
{
    $buf = '';
    foreach ($favorites as $key => $val) {
        $buf .= "{$key}: {$val},";
    }
    echo 'Test foreach($arr as $key => $val)' . "<br>\n";
    echo 'result: ' . ($buf === 'favcolor: red,favmovie: shawshank,favsong: Yellow submarine,' ? 'pass' : 'fail') . "<br><br>\n\n";
}
function test3()
{
    $arr = array(1, 2, 3);
    foreach ($arr as $i) {
        $i += 1;
    }
    echo 'Test foreach($arr as $val) { $val += 1 }' . "<br>\n";
    echo 'result: ' . ($i == 4 ? 'pass' : 'fail') . "<br><br>\n\n";
}
test1($favorites);
test2($favorites);
test3();
<?php

function test1(&$abc) : string
{
    return $abc;
}
function &test2(int $abc) : string
{
    return $abc;
}
function &test3(int &$abc) : string
{
    return $abc;
}
$a = 123;
var_dump(test1($a));
var_dump($a);
var_dump(test2($a));
var_dump($a);
var_dump(test3($a));
var_dump($a);
コード例 #10
0
<?php

use Lavoiesl\PhpBenchmark\Benchmark;
use Ovr\Bench\AssignOrNot\ReturnAfterAssignProperty;
use Ovr\Bench\AssignOrNot\ReturnWithoutAfterAssignProperty;
include_once __DIR__ . '/vendor/autoload.php';
$benchmark = new Benchmark();
function proxy($a, $b, $c)
{
    return true;
}
function test1()
{
    return proxy(...func_get_args());
}
function test2(...$args)
{
    return proxy(...$args);
}
$benchmark->add('...func_get_args()', function () use(&$str) {
    return test1(1, 2, 3);
});
$benchmark->add('....$args', function () use(&$str) {
    return test2(1, 2, 3);
});
$benchmark->setCount(10000000);
$benchmark->run();
コード例 #11
0
ファイル: file2.php プロジェクト: SandyS1/presentations
function test2($a, $b)
{
    test1($b, $a);
}
コード例 #12
0
<?php

/* Smarty version 2.6.27, created on 2013-09-16 20:17:57
   compiled from example7.tpl */
require_once SMARTY_CORE_DIR . 'core.load_plugins.php';
smarty_core_load_plugins(array('plugins' => array(array('function', 'yu', 'example7.tpl', 3, false), array('block', 'yu2', 'example7.tpl', 6, false))), $this);
?>

<h1>自定义函数yu 以function 方式显示</h1>
<?php 
echo test1(array('times' => '5', 'size' => '5', 'content' => "hello 栩坚", 'color' => 'red'), $this);
?>


<h1>自定义函数yu 以block 方式显示</h1>
<?php 
$this->_tag_stack[] = array('yu2', array('times' => '5', 'size' => '5', 'color' => 'blue'));
$_block_repeat = true;
test2($this->_tag_stack[count($this->_tag_stack) - 1][1], null, $this, $_block_repeat);
while ($_block_repeat) {
    ob_start();
    ?>
hello world<?php 
    $_block_content = ob_get_contents();
    ob_end_clean();
    $_block_repeat = false;
    echo test2($this->_tag_stack[count($this->_tag_stack) - 1][1], $_block_content, $this, $_block_repeat);
}
array_pop($this->_tag_stack);
コード例 #13
0
<?php

function sumArray($intArray)
{
    $total = 0;
    foreach ($intArray as $value) {
        $total += $value;
    }
    return $total;
}
function test1(Form $form)
{
    return 1;
}
function test2(array $array)
{
    return sumArray($array);
}
$test1 = test1(null);
assert($test1, 1);
$testArray = array(1, 2, 3);
$test2 = test2($testArray);
assert($test2, 6);
testEnd();
コード例 #14
0
ファイル: shuffle3.php プロジェクト: badlamer/hhvm
function main()
{
    var_dump(test1());
}
コード例 #15
0
ファイル: 546.php プロジェクト: badlamer/hhvm
<?php

function test1()
{
    $a = array(__FUNCTION__, __LINE__);
    return $a;
}
function test2()
{
    $a = array(__FUNCTION__, __LINE__);
    return $a;
}
var_dump(test1());
var_dump(test2());
コード例 #16
0
ファイル: by_ref.php プロジェクト: badlamer/hhvm
}
test1(...[1, 2, 3]);
$array = [1, 2, 3];
test1(...$array);
var_dump($array);
$array1 = [1, 2];
$array2 = [3, 4];
test1(...$array1, ...$array2);
var_dump($array1, $array2);
function test2($val1, &$ref1, $val2, &$ref2)
{
    $ref1++;
    $ref2++;
}
$array = [0, 0, 0, 0];
test2(...$array);
var_dump($array);
$array1 = [1, 2];
$array2 = [4, 5];
test1(...$array1, ...$array2);
var_dump($array1, $array2);
$a = $b = $c = $d = 0;
$array = [0, 0, 0, 0];
test2($a, ...$array);
var_dump($a, $array);
test2($a, $b, ...$array);
var_dump($a, $b, $array);
test2($a, $b, $c, ...$array);
var_dump($a, $b, $c, $array);
test2($a, $b, $c, $d, ...$array);
var_dump($a, $b, $c, $d, $array);
コード例 #17
0
ファイル: common.php プロジェクト: nextop/forp-ui
 /**
  * @ProfileGroup("Foo Group")
  * @ProfileCaption("Caption of bar2 #1 #2.")
  */
 function bar2($lambda, $object)
 {
     return test1();
 }
コード例 #18
0
<?php

function test1() : Generator
{
    (yield 1);
}
function test2() : Iterator
{
    (yield 2);
}
function test3() : Traversable
{
    (yield 3);
}
var_dump(test1(), test2(), test3());
コード例 #19
0
ファイル: 0024_GLOBALS.php プロジェクト: hslatman/phan
<?php

function test()
{
    $GLOBALS['a']['b'] = 1;
    $GLOBALS['c'] = 1;
}
function test1(array $arr)
{
}
function test2(int $arr)
{
}
test();
test1($c);
test2($a);
コード例 #20
0
ファイル: basic.php プロジェクト: badlamer/hhvm
<?php

function test1(...$args)
{
    var_dump($args);
}
test1();
test1(1);
test1(1, 2, 3);
function test2($arg1, $arg2, ...$args)
{
    var_dump($arg1, $arg2, $args);
}
test2(1, 2);
test2(1, 2, 3);
test2(1, 2, 3, 4, 5);
コード例 #21
0
ファイル: index.php プロジェクト: xiaoxiaoJun/phpper
<?php
header('Content-Type:text/html; charset=utf-8');

function test1(&$a){
	$a += 1;
}

$b = 5;
test1($b);
echo $b;

?>
コード例 #22
0
function test2($param)
{
    echo $param . ' test2';
}
function test3($param)
{
    echo $param . ' test3';
}
for ($i = 0; $i < count($argv); $i++) {
    if ($argv[$i] == '-s') {
        $param = $argv[$i + 1];
        run($param);
    } else {
        if ($argv[$i] == '-d') {
            $param = $argv[$i + 1];
            test1($param);
        } else {
            if ($argv[$i] == '-f') {
                $param = $argv[$i + 1];
                test2($param);
            } else {
                if ($argv[$i] == '--override') {
                    test3('override dan gelen  ');
                }
            }
        }
    }
}
if ($argc < 2) {
    $file = basename(__FILE__);
    print "STNC Autoincrement Generator" . CRLF;
コード例 #23
0
ファイル: grouping_runme.php プロジェクト: daxiazh/swig
<?php

require "tests.php";
require "grouping.php";
check::functions(array("test1", "test2", "do_unary", "negate"));
check::equal(5, test1(5), "5==test1(5)");
check::resource(test2(7), "_p_int", "_p_int==test2(7)");
check::globals(array(test3));
//check::equal(37,test3_get(),'37==test3_get()');
check::equal(37, check::get("test3"), '37==get(test3)');
//test3_set(38);
check::set(test3, 38);
//check::equal(38,test3_get(),'38==test3_get() after test3_set(37)');
check::equal(38, check::get(test3), '38==get(test3) after set(test)');
check::equal(-5, negate(5), "-5==negate(5)");
check::equal(7, do_unary(-7, NEGATE), "7=do_unary(-7,NEGATE)");
check::done();
コード例 #24
0
ファイル: bug42802.php プロジェクト: badlamer/hhvm
class bar
{
}
function test1(bar $bar)
{
    echo "ok\n";
}
function test2(\foo\bar $bar)
{
    echo "ok\n";
}
function test3(\foo\bar $bar)
{
    echo "ok\n";
}
function test4(\Exception $e)
{
    echo "ok\n";
}
function test5(\bar $bar)
{
    echo "bug\n";
}
$x = new bar();
$y = new \Exception();
test1($x);
test2($x);
test3($x);
test4($y);
test5($x);
コード例 #25
0
ファイル: 003.php プロジェクト: badlamer/hhvm
<?php

function test1()
{
    var_dump(func_get_args());
}
function test2($a)
{
    var_dump(func_get_args());
}
function test3($a, $b)
{
    var_dump(func_get_args());
}
test1();
test1(10);
test2(1);
test2();
test3(1, 2);
call_user_func("test1");
call_user_func("test3", 1);
call_user_func("test3", 1, 2);
class test
{
    static function test1($a)
    {
        var_dump(func_get_args());
    }
}
test::test1(1);
var_dump(func_get_args());
コード例 #26
0
ファイル: ref_new.php プロジェクト: Halfnhav4/pfff
<?php

// I have no idea what is the difference between using
// $o = new A(); and $o =& new A(); ...
// Drew: "Historically, '$a =& new A();' used to get special treatment
// because of how objects worked on PHP 4. HipHop currently has a bug
// where it converts '$a =& new A();' to '$a = new A();'
class A
{
}
function test1()
{
    $o = new A();
    var_dump($o);
    return $o;
}
$o = test1();
var_dump($o);
function &test2()
{
    $o =& new A();
    var_dump($o);
    return $o;
}
$o2 = test2();
var_dump($o2);
コード例 #27
0
ファイル: 166.php プロジェクト: badlamer/hhvm
}
function g()
{
}
function test1($a)
{
    $buf = '';
    foreach ($a as $s) {
        $buf .= f() . g() . 'h' . f() . 'h' . g();
    }
    foreach ($a as $s) {
        $buf .= $s . 'h' . $s;
    }
    return $buf;
}
var_dump(test1(array(1)));
function test2()
{
    return f() . g() . f() . g();
}
var_dump(test2());
function test3()
{
    return f() . g() . f() . g() . f() . g() . f() . g() . f();
}
var_dump(test3());
function test4()
{
    $s = f();
    $s .= 'foo' . 'bar' . f() . 'foo' . 'baz' . f() . 'fuz' . 'boo' . f() . 'fiz' . 'faz';
    $s .= f();
コード例 #28
0
<?php

function test1($a)
{
    $a = 100;
}
function test2(&$b)
{
    $b = 200;
}
$a = 10;
echo $a;
//10
test1($a);
echo $a;
//10
echo "<br/>";
$b = 20;
echo $b = 20;
//20
test2($b);
echo $b;
///200
コード例 #29
0
	<head>
		<title>Variable Scope</title>
	</head>
	<body>
		<?php 
// Set variable at global scope
$var = 1;
// Define function containing local variable
function test1()
{
    $var = 2;
    echo $var;
    echo "<br />";
}
// Call function
test1();
// Echo global
echo $var . "<br />";
echo "<hr />";
// Define function scope global variable
function test2()
{
    global $var;
    $var = 2;
    echo $var;
    echo "<br />";
}
// Call function
test2();
echo $var . "<br />";
echo "<hr />";
コード例 #30
0
ファイル: references.php プロジェクト: lihuibin/jphp
<?php

function test1()
{
    $x = 20;
    $y = 30;
    $z = 10;
    $func1 = function () use(&$x, &$y, $z) {
        $x = 40;
        $y = 50;
        $z = 60;
    };
    $func1();
    return $x + $y + $z;
}
$x = 20;
$y = 30;
$func2 = function () use(&$x, $y) {
    $x = 50;
    $y = 50;
};
if (($r = test1()) !== 100) {
    return "fail_1: {$r} != 100";
}
$func2();
if (($r = $x + $y) !== 80) {
    return "fail_2: {$r} != 80";
}
return 'success';