public function run() { $this->result = $this->ping->run(); if ($this->result > $this->config['max']) { $this->error = 'Maximum ping reached: ' . $this->result . '/' . $this->config['max']; } return parent::run(); }
2. No stopping execution before Test::run() 3. No Exceptions or PHP errors / warnings notices allowed 4. No redefining $test Hints: 1. Caesar 2. Magic methods 3. Requires a new feature of PHP 5.4 */ class Test { private $secret = 'Nyy lbhe Onfr ner orybat gb hf.'; private $callback; public final function run() { call_user_func($this->callback); return $this->secret . PHP_EOL; } public function __set($k, $v) { $key = $v[$v[$v]]; // $v is some kind of weird array $value = $v(); // and a callback! $this->{$key} = $value; } } $test = new Test(); // start editing here // end editing here echo $test->run();
<?php // run error_reporting(E_ALL & ~E_STRICT & ~E_NOTICE & ~E_DEPRECATED); $file = $_POST['file']; $test = $_POST['test']; ob_start(); $test = Test::run($file, $test); $output = ob_get_clean(); echo json_encode(array('pass' => $test, 'output' => $output));
<?php /** * @author ryan<*****@*****.**> * @desc 测试脚本 */ set_time_limit(0); require __DIR__ . DIRECTORY_SEPARATOR . 'loader.php'; class Test { public function run() { echo \Service\Service::test() . PHP_EOL; } } $test = new Test(); $test->run();
<?php // Require php compile with ZTS and PECL pthreads class Test extends Thread { public function run() { while (true) { echo $this->getCurrentThreadId(); sleep(1); } } } $t = new Test(); $t->run();
<pre>$ g++ -Wall -pedantic -o main main.cpp $ ./main Hello, world!</pre> Congratulations! You've just run your first C++ program. <?php $args = array_diff_key($_GET, array('debug' => '', 'style' => '')); $args = array_keys($args); $tests = empty($args) ? array() : explode(',', implode(',', $args)); if (!empty($tests)) { echo '<p>Showing only test(s) <strong>' . implode(', ', $tests) . '</strong>.</p>'; } hyperlight_test('python'); hyperlight_test('csharp'); hyperlight_test('VB'); hyperlight_test('simple.css', 'css'); hyperlight_test('../' . basename(__FILE__), 'php'); hyperlight_test('preg_helper.php', 'php'); hyperlight_test('pizzachili_api.h', 'cpp'); hyperlight_test('XML'); hyperlight_test('style.css', 'css'); ?> <h2>Test runs</h2> <?php require 'tests.php'; ?> <pre><?php Test::run('PregMerge'); ?> </pre><?php write_epilog(); }
} //乘法和除法类似省略... //实例化计算机对象的工厂类 class Factory { public static function create($operate) { return new $operate(); } } //测试终端类 class Test { function run() { //10+20=30 $operate = Factory::create('Jia'); $operate->a = 10; $operate->b = 20; echo $operate->getRes() . "\n"; //100-20=80 $operate = Factory::create('Jian'); $operate->a = 100; $operate->b = 20; echo $operate->getRes() . "\n"; } } //调用测试 $a = new Test(); $a->run();
<?php class Test { public function run() { $r = $this->my_parse_m(); var_dump($r); return $r; } public function my_parse_m() { $test = true; if ($test === true) { $a = 'b'; } else { return false; } // flush(); return true; } } $t = new Test(); var_dump($t->run());
} static function load_config() { $time = time(); $config = (include ROOT_PATH . DS . 'config.php'); foreach ($config as $id => $task) { // 先支持秒(, *) 这两种 $ret = ParseCrontab::parse($task["time"], $time); // 设置每秒的任务 foreach ($ret as $sec) { self::$turntable[$sec][$id] = $task; } } } static function do_something($interval) { // 在执行获取任务的时候,只获取当前秒的任务 $tasks_arr = self::$turntable; $current_sec = intval(date('s')); if (!isset($tasks_arr[$current_sec])) { return false; } $tasks = $tasks_arr[$current_sec]; foreach ($tasks as $id => $task) { (new Process())->create_process($task); } return true; } } Test::run();
public function index() { Test::run(); }
$template->parse("\n {foreach \$number in \$numbers}{echo \$number_i},{echo \$number},{/foreach}"); $processed = $template->process(array("numbers" => array(1, 2, 3))); return trim($processed) == "0,1,1,2,2,3,"; }, "Template parses foreach tag", "Template"); Test::add(function () use($template) { $template->parse("\n {for \$number in \$numbers}{echo \$number_i},{echo \$number},{/for}\n "); $processed = $template->process(array("numbers" => array(1, 2, 3))); return trim($processed) == "0,1,1,2,2,3,"; }, "Template parses for tag", "Template"); Test::add(function () use($template) { $template->parse("\n {if \$check == \"yes\"}yes{/if}\n {elseif \$check == \"maybe\"}yes{/elseif}\n {else}yes{/else}\n "); $yes = $template->process(array("check" => "yes")); $maybe = $template->process(array("check" => "maybe")); $no = $template->process(array("check" => null)); return $yes == $maybe && $maybe == $no; }, "Template parses if, else and elseif tags", "Template"); Test::add(function () use($template) { $template->parse("\n {macro foo(\$number)}\n {echo \$number + 2}\n {/macro}\n\n {echo foo(2)}\n "); $processed = $template->process(); return $processed == 4; }, "Template parses macro tag", "Template"); Test::add(function () use($template) { $template->parse("\n {literal}\n {echo \"hello world\"}\n {/literal}\n "); $processed = $template->process(); return trim($processed) == "{echo \"hello world\"}"; }, "Template parses literal tag", "Template"); ////////////////////////////// $tests = Test::run(); echo '<pre>'; print_r($tests); echo '</pre>';