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 
    }
示例#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);
     }
 }
示例#3
0
function test2($i)
{
    echo $i, '<br/>';
    //3
    if ($i >= 0) {
        test2($i - 1);
        //test2(2)
        /*
        echo $i,'<br/>';//2
        		if($i>=0){
        			test2($i-1);//test2(1)
        				echo $i,'<br/>';//1
        				if($i>=0){
        					test2($i-1);//test2(0)
        						echo $i,'<br/>';//0
        						if($i>=0){
        							test2($i-1);//test2(-1)
        								echo $i,'<br/>';//-1
        								if($i>=0){
        									test2($i-1);
        								}
        								echo $i,'<br/>';//-1
        						}
        						echo $i,'<br/>';//0
        				}
        				echo $i,'<br/>';//1
        		}
        		echo $i,'<br/>';//2
        */
    }
    echo $i, '<br/>';
    //3
}
示例#4
0
function test()
{
    function test2()
    {
        echo "<p>Test 2 function </p>";
    }
    test2();
}
示例#5
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();
示例#6
0
文件: 010.php 项目: badlamer/hhvm
function test($a, $b)
{
    var_dump($a === $b);
    test2($a, $b);
}
示例#7
0
文件: 1091.php 项目: badlamer/hhvm
function test(&$some_ref)
{
    $some_ref = 42;
}
test($some_ref = 1);
var_dump($some_ref);
$var = null;
test($var);
var_dump($var);
$var = null;
test($some_ref = $var);
var_dump($some_ref, $var);
$var = null;
test($some_ref =& $var);
var_dump($some_ref, $var);
function test2($some_ref)
{
    $some_ref = 42;
}
test2($some_ref = 1);
var_dump($some_ref);
$var = null;
test2($var);
var_dump($var);
$var = null;
test2($some_ref = $var);
var_dump($some_ref, $var);
$var = null;
test2($some_ref =& $var);
var_dump($some_ref, $var);
示例#8
0
 function test($B)
 {
     test2($B);
 }
示例#9
0
function test1()
{
    test2();
    print_r(debug_backtrace());
}
示例#10
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);
示例#11
0
<?php

function test()
{
    static $var = 1 + 2.5;
    return $var;
}
function test2(int $arg)
{
}
test2(test());
<?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);
示例#13
0
 function innerFunc($val, $x, $y)
 {
     return test2($val, $x + $y);
 }
<?php

class A
{
    public static $var;
}
function test(&$arg)
{
    $arg = 2;
}
function test2(&$arg2)
{
    $arg2 = "abc";
}
function test3(array $arg)
{
}
test(A::$var);
test2(A::$var);
test3(A::$var);
示例#15
0
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
//
// ****************************************************************************
echo "<h4>Modules</h4><hr><span style=\"font-size:90%\">\n";
if (isLvl5("Anchoring") && skillLvl("Starbase Defense Management") != -1) {
    test5("Starbase Defense Management", "Pos Guns");
}
test("Cynosural Field Generator I", "Cyno Gen");
echo "<br>";
if (!test2("100MN Microwarpdrive II", "T2 MWDs")) {
    test("100MN Microwarpdrive I", "T1 MWDs");
}
test("Large Shield Extender II", "LSE II");
test("Invulnerability Field II", "Invuln II");
test("Energized Adaptive Nano Membrane II", "EANM II");
test("Damage Control II", "DCU II");
test("1600mm Reinforced Rolled Tungsten Plates I", "1600mm RT");
test("Sensor Booster II", "SB II");
test("Tracking Computer II", "TC II");
test("Tracking Enhancer II", "TE II");
test("Power Diagnostic System II", "PDU II");
test("Reactor Control Unit II", "RCU II");
test("Gyrostabilizer II", "T2 dmg mods");
if (!test2("Covert Ops Cloaking Device II", "CovOps Cloak")) {
    test("Prototype Cloaking Device I", "Proto Cloak");
}
test("Warp Disruptor II", "T2 Tackle");
test("Stasis Webifier II", "Webifier II");
test("Large Shield Booster II", "LSB II");
test("Large Armor Repairer II", "LAR II");
echo "</span>";
示例#16
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

/* 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);
示例#18
0
function test($aParameter)
{
    return test2();
}
<?php

$a = 1;
$b = 1;
function test(&$x, &$y)
{
    $y++;
    $x *= 2;
    return TRUE;
}
function test2($x, $y)
{
    $y++;
    $x *= 2;
    return TRUE;
}
// affects $a and $b because values are by reference
test($a, $b);
test($a, $b);
// NOTE: has no effect on $a and $b outside test2()
test2($a, $b);
test2($a, $b);
// output: 4, 3
var_dump($a, $b);
示例#20
0
<?php

function test(array $array)
{
    $closure = function () use($array) {
        print_r($array);
        (yield "hi");
    };
    return $closure();
}
function test2(array $array)
{
    $closure = function () use($array) {
        print_r($array);
        (yield "hi");
    };
    return $closure;
    // if you return the $closure and call it outside this function it works.
}
$generator = test(array(1, 2, 3));
foreach ($generator as $something) {
}
$generator = test2(array(1, 2, 3));
foreach ($generator() as $something) {
}
$generator = test2(array(1, 2, 3));
echo "okey\n";
示例#21
0
<?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();
示例#22
0
<?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);
示例#23
0
 function test3()
 {
     test2();
 }
示例#24
0
        $af[1] = $_POST['af1'];
        $af[2] = $_POST['af2'];
        $af[3] = $_POST['af3'];
        $af[4] = $_POST['af4'];
        $count = $wpdb->get_var('SELECT count(*) FROM ' . $t_ap_more_content . ' WHERE config_id =' . $_POST['id'] . ' AND option_type=1');
        if ($count == 0) {
            $wpdb->query($wpdb->prepare("insert into {$t_ap_more_content}(config_id,option_type,content) values (%d,1,%s)", $_POST['id'], json_encode($af)));
        } elseif ($count == 1) {
            $wpdb->query($wpdb->prepare("update {$t_ap_more_content} set content = %s WHERE config_id = %d and option_type=1 ", json_encode($af), $_POST['id']));
        }
    } else {
        $wpdb->query('delete from ' . $t_ap_more_content . ' where config_id =' . $_POST['id'] . ' and option_type=1');
    }
    $saction2 = $_POST['saction2'];
    if ($saction2 == 'test2') {
        test2($_POST['id']);
    } else {
        echo '<div id="message" class="updated fade"><p>' . __('Updated!', 'wp-autopost') . '</p></div>';
    }
    $showBox2 = true;
}
// end if($saction=='save2'){
if ($saction == 'updateAll') {
    echo '<div class="updated fade"><p><b>' . __('Being processed, the processing may take some time, you can close the page', 'wp-autopost') . '</b></p></div>';
    ob_flush();
    flush();
    //$m1=getMemUsage();
    fetchAll();
    //$m2=getMemPUsage();
    //echo '<div class="updated fade"><p>This update max used <strong>', getUsedMemory($m2-$m1) ,'</strong> memorys</p></div>';
}
}
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;
    print "Usage: php -f {$file} -- -s komut \n [--override -d output_dir -f output_filename]" . CRLF;
    exit;
}
示例#26
0
echo '<hr />';
function testName()
{
    echo __FUNCTION__;
    //得到当前函数的名称
}
testName();
//testName;
echo '<hr />';
/*
 func_num_args():得到传入函数参数的个数
func_get_arg($index):根据下标得到指定参数
func_get_args():得到所有传入进来的参数,得到是一个数组
*/
function test2()
{
    echo func_num_args();
    echo '<br/><br/>';
    echo func_get_arg(0), '<br/>';
    echo func_get_arg(1), '<br/>';
    echo func_get_arg(2), '<br/>';
    echo func_get_arg(3), '<br/>';
    echo func_get_arg(4), '<br/>';
    for ($i = 0, $count = func_num_args() - 1; $i <= $count; $i++) {
        //遍历数组返回键值
        echo func_get_arg($i);
        echo '<br/>';
    }
}
test2(1, 23, 4, 5, 6, 6, 54, 4, 'a', 'b', 'c', 'd', 'f', 'username');
示例#27
0
}
$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
echo "\n\ntest3 (Assigned):\n";
$x = array();
$x[0] = 1;
$x[1] = 2;
$x[2] = 3;
unset($x[2]);
$y = $x;
$y[] = 5;
var_dump($y);
示例#28
0
 /**
  * Test whether sandbox custom validation error handler intercepts validation Errors
  */
 public function testCustomValidationErrorHandler()
 {
     $this->expectException('PHPSandbox\\Error');
     $this->sandbox->setValidationErrorHandler(function ($error) {
         throw $error;
     });
     $this->sandbox->execute(function () {
         test2();
     });
 }
}
// 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 />";
// Define function scope global variable
function test3()
{
    static $var = 2;
    echo $var;
    echo "<br />";
    $var++;
}
// Call function
test3();
test3();
test3();
?>
示例#30
0
<?php

define('MY_CONST', 10);
const ABC = 10;
function test($x = MY_CONST, $y = ABC)
{
    return $x + $y;
}
if (($x = test()) !== 20) {
    return 'fail_1: ' . $x;
}
if (test(12) !== 22) {
    return 'fail_2';
}
class FOO
{
    const MY_CONST = 20;
}
function test2($x = FOO::MY_CONST)
{
    return $x;
}
if (test2() !== 20) {
    return 'fail_3: class::const';
}
if (test2(22) !== 22) {
    return 'fail_4';
}
return 'success';