function command_parse() { global $DB, $Core, $Parse, $Security, $Base, $Style; if (!$Security->allowed()) { return; } $include = implode("/", module()); if (file_exists("module/{$include}/main.php")) { $dir = ""; foreach (module() as $module) { $dir .= "{$module}/"; $shared = "module/{$dir}shared.php"; if (file_exists($shared)) { include $shared; } } require_once "module/{$include}/main.php"; if (function_exists(command())) { eval(command() . "();"); } if (file_exists("module/{$include}/.content/" . func() . ".php")) { if (!get('ajax') && !get('xml')) { require_once "module/{$include}/.content/" . func() . ".php"; } } } else { $Base = new Base(); $Base->title("Invalid Module"); $Base->Header(); $Base->Footer(); } }
function funcfunc() { try { func(); } catch (Exception $ex) { throw $ex; } }
function debug() { print "<strong>query string:</strong> {$_SERVER['QUERY_STRING']}\n\n"; print "<strong>module:</strong> " . implode("-", module()) . "\n"; print "<strong>function:</strong> " . func() . "\n"; print "<strong>method:</strong> " . method() . "\n\n"; print "<strong>include:</strong> /module/" . implode("/", module()) . "/main.php\n\n"; print "<strong>run:</strong> " . command() . "\n\n"; }
function test2() { function func($fname = array('ball')) { return $fname; } $result1 = func(); echo "Test that empty array default parameter works as expected.<br>\n"; echo 'result: ' . ($result1[0] == 'ball' ? 'pass' : 'fail') . "<br><br>\n\n"; }
/** * Write a real-valued function Fact2(N) that returns a double factorial N!!: * N!! = 1·3·5·…·N, if N is an odd number; * N!! = 2·4·6·…·N otherwise * (N is a positive integer; the real return type allows to avoid the integer * overflow during the calculation of the double factorials for large values of N). * Using this function, find the double factorials of five given integers. */ function Fact2($n) { if ($n % 2 == 0) { $result = func($n); $result = 'even ' . $result; } else { $result = func($n); $result = 'odd ' . $result; } return $result; }
function foo4() { global $ar; foreach ($ar as $y) { func(12, new Dtor(), mt_rand(), func(mt_rand(), blar($y))); } try { } catch (Exception $x) { echo "Bad\n"; } }
function Dispatch() { $param = "/"; $arr = array_diff($this->command->getParameters(), array('')); $param = $param . $this->command->getCommandName(); foreach ($arr as $s) { $param = $param . "/" . $s; } $this->readyUrlRoute($this->url, $param); $this->controller->setParameters($this->command->getCommandName(), $this->command->getParameters()); func(array($this->controller, $this->callback)); }
function func($id, $sd) { $a = array(); $db = new PDO('mysql:host=localhost;dbname=verse;charset=utf8', 'root', 'V3r5e'); $stmt = $db->query('SELECT * from tree where parent=' . $id . ' and vid=' . $sd . ''); if (isset($stmt)) { while ($line = $stmt->fetchAll(PDO::FETCH_ASSOC)) { foreach ($line as $col_val) { $a[] = array("name" => $col_val['name'], "children" => func($col_val['id'], $_GET['hari'])); } } } return $a; }
private function doSomething() { $this->has($this->nested("function calls!", 12.4)); $var = 'single quoted string'; $var->supports->dotNotation = "also" . "supports" . 'string' . $concatenation; $name = func(self::SOME_CONST); $name = func(self::$static_property); $do->somethingWith($this); $array_style_one = array('list', 'of', 4, $things); $nested_arrays = array('stuff', $with, array('stuff' => $between)); $arrays = array('name' => 'russ', 'phone_number' => '1800flowers'); $arrays[$foo] = 'bar'; $var->supports($dotNotation, 'for functions!'); return $x < $y ? true : false; }
function pleac_Interpolating_Functions_and_Expressions_Within_Strings() { #----------------------------- echo $var1 . func() . $var2; // scalar only #----------------------------- // PHP can only handle variable expression without operators // $answer = "STRING ${[ VAR EXPR ]} MORE STRING"; #----------------------------- $phrase = "I have " . ($n + 1) . " guanacos."; // PHP cannot handle the complex exression: ${\($n + 1)} #----------------------------- // Rest of Discussion is not applicable to PHP #----------------------------- // Interpolating functions not available in PHP #----------------------------- }
function allowed() { global $_allowed_; if (!session('id')) { if (!in_array(implode("-", module()) . func(), $_allowed_)) { $Base = new Base(); $Base->type(ERROR); $Base->title(ERROR_MUST_LOGIN); $Base->header(); $Base->footer(); return false; } else { return true; } } else { return true; } }
function get_index() { $vars = array('isManager' => $this->can('manager'), 'can' => array(), 'user' => $this->user(false)); $query = Order::with('manager')->name('o'); Event::fire('order.list.query', array($query, $this, &$vars['can'])); $rows = S::keys($query->get(), '?->id'); if ($rows) { foreach ($rows as &$order) { $order->current = false; } $current = static::detectCurrentOrder(); $current and $rows[$current->id]->current = true; Event::fire('order.list.populate', array(&$rows, $this, &$vars)); } $vars['rows'] = func('to_array', $rows); Event::fire('order.list.vars', array(&$vars, $this)); return $vars; }
function gen() { if ((yield $foo)) { } elseif ((yield $foo)) { } if ((yield $foo)) { } elseif ((yield $foo)) { } while ((yield $foo)) { } do { } while ((yield $foo)); switch ((yield $foo)) { } (yield $foo); die((yield $foo)); func((yield $foo)); $foo->func((yield $foo)); new Foo((yield $foo)); }
function drawsolid() { global $p3; global $xmax; global $xmin; global $ymax; global $ymin; global $zmin; global $zmax; global $nxpoints; global $nypoints; Plot3D_clear($p3, BLACK); Plot3D_start($p3); $dx = 1.0 * ($xmax - $xmin) / $nxpoints; $dy = 1.0 * ($ymax - $ymin) / $nypoints; $cscale = 240.0 / ($zmax - $zmin); $x = $xmin; for ($i = 0; $i < $nxpoints; $i++) { $y = $ymin; for ($j = 0; $j < $nypoints; $j++) { $z1 = func($x, $y); $z2 = func($x + $dx, $y); $z3 = func($x + $dx, $y + $dy); $z4 = func($x, $y + $dy); $c1 = $cscale * ($z1 - $zmin); $c2 = $cscale * ($z2 - $zmin); $c3 = $cscale * ($z3 - $zmin); $c4 = $cscale * ($z4 - $zmin); $c = ($c1 + $c2 + $c3 + $c4) / 4; if ($c < 0) { $c = 0; } if ($c > 239) { $c = 239; } Plot3D_solidquad($p3, $x, $y, $z1, $x + $dx, $y, $z2, $x + $dx, $y + $dy, $z3, $x, $y + $dy, $z4, $c + 16); $y = $y + $dy; } $x = $x + $dx; } }
function pleac_Skipping_Selected_Return_Values() { // The 'list' keyword [looks like a function but is actually a special language // construct] may be used to perform multiple assignments from a numerically // indexed array of values, and offers the added bonus of being able to skip // assignment of one, or more, of those values function func() { return array(3, 6, 9); } // ------------ list($a, $b, $c) = array(6, 7, 8); // Provided 'func' returns an numerically-indexed array, the following // multiple assignment will work list($a, $b, $c) = func(); // Any existing variables no longer wanted would need to be 'unset' unset($b); // As above, but second element of return array discarded list($a, , $c) = func(); // ---------------------------- // Care needed to ensure returned array is numerically-indexed list($dev, $ino, , , $uid) = array_slice(array_values(stat($filename)), 0, 13); }
/** * This file is part of Benchmark * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. * * @author Nicolò Martini <*****@*****.**> */ include '../vendor/autoload.php'; ini_set('xdebug.var_display_max_depth', '10'); function func() { } $func = 'func'; $bench = new \Nicmart\Benchmark\FixedSizeEngine(); $args = array_fill(0, 5, null); $bench->register('direct', 'Direct call', function () use($args) { func($args[0], $args[1], $args[2], $args[3], $args[4]); }, true)->register('cuf', 'call_user_func', function () use($args) { call_user_func('func', $args[0], $args[1], $args[2], $args[3], $args[4]); }, true)->register('cufa', 'call_user_func_array', function () use($args) { call_user_func_array('func', $args); }); $bench->benchmark(100); $bench->benchmark(100); $bench->benchmark(100); $bench->benchmark(100); $bench->benchmark(1000); $groups[] = $bench->getResults(); $template = new \Nicmart\Benchmark\PHPTemplate(); echo $template->render(array('groups' => $groups));
{ return strlen($str); } public static function instance() { return new self(); } public function strlenFunction() { return 'strlen'; } } function func() { return array('func'); } function test() { return 'test'; } testStrict(checkFunc('strlen')('four'), 4, 'func()()'); testStrict($checkFunc('strlen')('four'), 4, '$func()()'); testStrict(Test::checkFunc('strlen')('four'), 4, 'Class::method()()'); testStrict(Test::checkFunc(array('Test', 'strlen'))('four'), 4, 'Class::method(array(...))()'); testStrict(${$checkFunc}('strlen')('four'), 4, '$$func()()'); testStrict(Test::${$checkFunc}('strlen')('four'), 4, 'Class::$$method()()'); testStrict(Test::instance()->strlenFunction()('four'), 4, 'complex resolution'); testStrict(func()[0]()[0](), array('func'), 'func()[0]()[0]() (depends on arrayAccess)'); testStrict(test()()(), 'test', 'func()()()'); ?> </pre>
function disp_order() { $arr = array(); $con = new mysqli("server29.000webhost.com", "a7914922_root", "1234asdf", "a7914922_hotels"); $res = $con->query("select * from cart"); $res1 = $con->query("select * from cart"); global $i, $j; $i = 0; $row1 = $res1->fetch_assoc(); $row1 = $res1->fetch_assoc(); include 'cart.php'; $rest_id = $row1['res_id']; $row = $res->fetch_assoc(); echo "<br/><br/>USERNAME : "******" <br/>"; echo "<div class='container'><table class='table table-striped'>"; echo "<th>ITEM</th>" . "<th>QTY</th>" . "<th>PRICE</th>" . "<th></th>"; while ($row = $res->fetch_assoc()) { //$row = $res->fetch_assoc(); echo "<tr>"; $arr[$i] = $row['item']; $y = $row['item']; echo "<td>" . $row['item'] . "</td><td>" . $row['qty'] . "</td><td>" . $row['tot_price'] . "</td><td><button class='someclass btn btn-info' name='{$y}' value='{$y}'>Edit</button></td><td></td></tr>"; $i++; } $j = $i; echo "</table></div><br/>"; //echo $arr[0]."arr[0]"; echo "<form method='post'>"; $k = 0; echo " <div class='container'><button type='button' class='btn btn-info' data-toggle='collapse' data-target='#demo1' >Want to delete an item?</button><div id='demo1' class='collapse'>"; while ($k < $j) { echo "<input type='checkbox' name='{$k}' value='{$arr[$k]}'> " . $arr[$k] . "<br><br>"; $k++; } echo "<input type='submit' name='delete' value='Delete selected item'></form></div></div><br>"; echo " <div class='container'><button type='button' class='btn btn-info' data-toggle='collapse' data-target='#demo3' >Add an item?</button><div id='demo3' class='collapse'>"; echo "<br>Press back to add more items..</div></div>"; if (isset($_POST['reorder'])) { func1($rest_id); } //if($rest_id ==3) echo "<button type='button' name='re-order' onclick='document.location.href='pbay.php''>RE-ORDER</button>"; if (isset($_POST['delete'])) { func($i); } }
// 预定义一个用来存储转换值的空数组 /* 将每一个传入的参数(非数组)组合成关联数组, 键名为 $defaults 数组的键名, 值为传入的参数 */ for ($i = 0; $i < count($argInput); $i++) { if ($argInput[$i] == null || false) { continue; } // 当参数为 null 或 false 时不转换并且丢弃该参数 $argTrans[$defaultsKey[$i]] = $argInput[$i]; } $arguments = array_merge($arguments, $defaults, $argTrans); } } else { $arguments = $defaults; // 入如果没有传入参数, 则使用默认值 } return $arguments['name'] . ' is a ' . $arguments['role'] . '.' . "\n"; } echo func(array('name' => 'Ayon', 'role' => 'Web Builder')); // Ayon is a Web Builder. echo func(array('name' => 'Ayon')); // Ayon is a student. echo func(array('role' => 'Web Builder')); // Hyurl is a Web BUilder. echo func('Ayon', 'Web Builder'); // Ayon is a Web Builder. echo func('Ayon'); // Ayon is a student. echo func(null, 'Web Builder'); // Hyurl is a Web Builder. echo func(); // Hyurl is a student.
use Guzzle\Http\Message\Response; function func($var) { if (!$var) { $S3 = new S3Exception("hello word"); $S3->setExceptionCode(400); $S3->setExceptionType("Client"); $S3->setResponse(new Response(405)); throw $S3; } } // $r = ObsClient::isValidBucketName("123"); // var_dump($r); $client = ObsClient::factory(array('key' => 'C6840CE16E23C6F06EFF', 'secret' => 'RueC/EXFyvTbWGG6VkenF82w5pIAAAFNbiPG8EfN', 'endpoint' => 'http://129.7.182.2:5080', 'signature' => 's3')); try { func(0); } catch (S3Exception $e) { echo $e; } echo "--------------------------------\n"; //ssl认证 $client->setSslVerification(false, false, 0); $resp = $client->listBuckets(); var_export($resp); // $resp = $client->createBucket(array( // 'Bucket'=>'123456-2', // 'ACL'=>'log-delivery-write', // 'LocationConstraint'=>'abc' // )); // var_export($resp); // $resp = $client->HeadBucket(array(
<? require_once("filter.php"); while (1) { $number1=rand(10000,99999); $number2=rand(10000,99999); $number=$number1.$number2; echo $number."<br>"; func ($number); } ?>
<?php $tainted = $_GET["tainted"]; function func($a, $b) { if ($a > 3) { $ret = $b; } else { $ret = "hello"; } echo "stuff " . $ret; return $ret; } $a = func(5, $tainted);
if ($ignoreCase) { return strtolower($str1) == strtolower($str2); } else { return $str1 == $str2; } } echo strIsEqual("Ivan", "Ivan", true); echo strIsEqual("Ivan", "bai Ivan", true); echo "<hr>"; function func(&$param) { $param = 5; return $param * 2; } $p = 100; echo func($p); echo "\n"; echo $p; echo "<hr>"; function calcSum() { $sum = 0; foreach (func_get_args() as $arg) { $sum = $sum + $arg; } return $sum; } echo calcSum(1, 2, 4, 5, 6, 7, 8) . "<br>"; echo calcSum(); echo "<hr>"; function moveInt($a, $b)
function command() { return func() . "_" . method(); }
function test() { $insert_args = ['queue_table' => self::QUEUE_TABLE, 'spot_id' => intval($dest_data[self::DEST_DATA_FIELD_SPOT_ID]), 'table' => \SQL::qstr_real($dest_data[self::DEST_DATA_FIELD_TABLE], $dbh), 'obj_hash' => \SQL::qstr_real($object_data_hash, $dbh), 'obj_data' => \SQL::qstr_real($object_data, $dbh), 'created' => \SQL::qstr_real(\SQL::now(), $dbh), 'test' => func() ? 'a' : 'b']; }
$rightcount = 0; $rightindex = 0; foreach ($mstr as $key => $value) { if ($value == "(") { $leftcount++; $leftindex = $key; } if ($value == ")") { $rightcount++; $rightindex = $key; if ($rightcount > $leftcount) { echo "Неверно<br>"; return; } } } if ($leftcount == $rightcount and $leftindex < $rightindex) { echo "Верно<br>"; } else { echo "Неверно<br>"; } } func("a+b+c)"); func("(b+(c+a))"); func("b+(c+a))"); func("(a+b)+(a+b)"); func("(a+b)+a+b)"); func("()a+b)+(a+b()"); ?> </body>
/** * 返回引用示例2 */ function &func($a, $b) { static $result = 0; $result += $a + $b; echo $result . PHP_EOL; return $result; } $a = $b = 10; $c = func($a, $b); $c = func($a, $b); $d =& func($a, $b); $d = 10; $d = func($a, $b); exit; } if ($which == 1) { /** * 返回引用示例1 */ class foo { public $value = 20; function &getValue() { return $this->value; } } $obj = new foo();
function &getRef() { global $c; return $c; } $c1 =& getRef(); $c1++; var_dump($c); // 6 var_dump($c1); // 6 function &collector() { static $collection = array(); return $collection; } array_push(collector(), 'foo'); //array_push(&collector(), 'foo'); // fatal var_dump(collector()); // foo is inside function func(&$arraykey) { return $arraykey; } $array = array('a', 'b', 'c'); foreach (array_keys($array) as $key) { $y =& func($array[$key]); $z[] =& $y; } var_dump($z); // c, c, c
<?php define('VALUE', 1); function func($params) { var_dump($params); } func(array('key' => @VALUE));
// Fired after successfully adding a post with attachments and all required database // and other changes. // //* $options hash - the same as in post.attach plus 'attachments' hash of File. Event::listen(VANE_NS . 'post.added', function (array $options) { extract($options, EXTR_SKIP); $poster = $block->user(false); $to = User::all(arrize(\Vane\Current::config('general.post_notify_users'))); if ($type === 'order' and $order = Order::find($object)) { foreach (array('user', 'manager') as $field) { $to[] = $order->{$field}()->first(); } } foreach ($to as $recipient) { if (!$poster or $poster->email != $recipient->email) { \Vane\Mail::sendTo($recipient->emailRecipient(), 'vanemart::mail.order.post', array('order' => $order->to_array(), 'user' => $block->user()->to_array(), 'recipient' => $recipient->to_array(), 'post' => $post->to_array(), 'files' => func('to_array', $attachments))); } } }); // Fired after post.added if post is attached to an object. // //* $object Eloquent //* $options hash - the same as in post.added. Event::listen(VANE_NS . 'post.object_ref', function (&$object, array $options) { $object->updated_at = new \DateTime(); }); /*----------------------------------------------------------------------- | THUMB BLOCK |----------------------------------------------------------------------*/ // Fired after creating and configuring ThumbGen instance for custom setup. //