コード例 #1
1
ファイル: SyntaxChecker.php プロジェクト: aik099/PhpMetrics
 /**
  * Check syntax of file
  *
  * @param $filename
  * @return int
  */
 public function isCorrect($filename)
 {
     if (1 === version_compare('5.0.4', PHP_VERSION)) {
         return php_check_syntax($filename);
     } else {
         $output = shell_exec(sprintf('php -l %s 2>&1', escapeshellarg($filename)));
         return preg_match('!No syntax errors detected!', $output);
     }
 }
コード例 #2
1
ファイル: source6056.php プロジェクト: bjork/php-compat-info
 /**
  * Sample code to check max php version
  *
  * @return void
  */
 function testMaxVersion()
 {
     // PHP 5 <= 5.0.4
     $res = php_check_syntax('bug6581.php');
     $array1 = array('blue' => 1, 'red' => 2, 'green' => 3);
     $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7);
     // PHP 5 >= 5.1.0RC1
     $diff = array_diff_key($array1, $array2);
 }
コード例 #3
1
ファイル: SyntaxChecker.php プロジェクト: truffo/PhpMetrics
 /**
  * Check syntax of file
  *
  * @param $filename
  * @return int
  */
 public function isCorrect($filename)
 {
     if (1 === version_compare('5.0.4', PHP_VERSION)) {
         return php_check_syntax($filename);
     }
     $php = 'php';
     if (0 >= version_compare('5.4.0', PHP_VERSION)) {
         $php = PHP_BINARY;
     }
     $output = shell_exec(sprintf('"%s" -l %s 2>&1', $php, escapeshellarg($filename)));
     return preg_match('!No syntax errors detected!', $output);
 }
コード例 #4
1
ファイル: index.php プロジェクト: a-v-s/php_check_syntax
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
POSSIBILITY OF SUCH DAMAGE. 
*/
// This function was removed from PHP in version 5.0.5
// Check syntax via command line. How portable is this code?
// Does the command line output depend on the servers locale?
if (!function_exists("php_check_syntax")) {
    function php_check_syntax($filename, &$error_message)
    {
        $cmd = "php -l " . __DIR__ . "/{$filename}";
        $message = shell_exec($cmd);
        $result = strpos($message, "No syntax errors detected") !== false;
        if (!$result) {
            $error_message = $message;
        }
        return $result;
    }
}
if (php_check_syntax("file_with_syntax_error.php", $blaat)) {
    echo "OK<BR>";
} else {
    echo "ERROR {$blaat}<br>";
}
if (php_check_syntax("index.php")) {
    echo "OK<BR>";
} else {
    echo "ERROR<br>";
}
echo "hello!";
コード例 #5
1
ファイル: fileinc4.php プロジェクト: QSC-PLT/17eyes
<?php

include $GET_['x'];
include_once $GET_['x'];
php_check_syntax($GET_['x']);
require $GET_['x'];
require_once $GET_['x'];
runkit_import($GET_['x']);
set_include_path($GET_['x']);
virtual($GET_['x']);
コード例 #6
1
ファイル: xpi.php プロジェクト: gpuenteallott/rox
function ewiki_xpi_install($xpi_install_fn, $access, $jsi_access, $jsi_support)
{
    ewiki_xpi_load_registry($registry, $registry_hash);
    #-- load (possibly remote) .xpi file
    $xpi = ewiki_xpi_read($xpi_install_fn, "rb");
    if (!$xpi) {
        return "not a valid .xpi plugin (or wrong/inacceptable xpi plugin type/version)";
    }
    if (strlen($xpi["id"]) < 3) {
        return "missing .xpi header";
    }
    #-- it's a .jpi plugin
    if (($access || $jsi_access) && $xpi["type"] == "jpi") {
        #-- compile from JS (WikiScript) into sandboxed PHP
        if ($jsi_support) {
            $xpi["type"] = "page";
            js_compile($xpi["code"]);
            $xpi["code"] = NULL;
            $xpi["code"] = jsa_generate();
        } else {
            return "<b>ERROR</b>: cannot handle .jpi plugins without installed JavaScript interpreter";
        }
        if ($GLOBALS["js_err"]) {
            ewiki_log("failed compiling .jpi plugin '{$xpi['id']}'", 0);
            return "<b>ERROR</b>: broken .jpi plugin!";
        }
    } elseif (!$access) {
        return "<b>ERROR</b>: You don't have permission to install this type of plugin.<br /><br />";
    }
    #-- proceed with setup
    $xpi["state"] = 1;
    if (function_exists("php_check_syntax")) {
        if (!php_check_syntax($xpi["code"])) {
            return "<b>ERROR</b>: plugin code is broken";
        }
    }
    #-- create new database entry
    $new = ewiki_new_data($xpi["id"], EWIKI_DB_F_SYSTEM | EWIKI_DB_F_EXEC);
    $new["content"] = $xpi["code"];
    unset($xpi["code"]);
    #-- check for old version
    if ($access) {
        $old = ewiki_db::GET($new["id"]);
        if ($old["version"]) {
            $new["version"] = $old["version"] + 1;
            $o .= "(overwriting plugin [version {$old[version]}])<br />";
        }
    }
    #-- store plugin into database
    if (ewiki_db::WRITE($new)) {
        ewiki_log("successfully installed .xpi plugin '{$xpi['id']}'", 0);
        $o .= $xpi["type"] == "page" ? ewiki_link($xpi[id]) : "<b>{$xpi[id]}</b>";
        $o .= " plugin stored. ";
        #-- update .xpi registry
        $registry[$xpi["id"]] = $xpi;
        $registry_hash["content"] = serialize($registry);
        ewiki_data_update($registry_hash);
        $registry_hash["version"]++;
        ewiki_db::WRITE($registry_hash);
    } else {
        $o .= "<b>error</b> saving";
        ewiki_log("error installing .xpi/.jpi plugin '{$xpi['id']}'", 0);
    }
    return $o;
}
コード例 #7
0
ファイル: test_funcs.php プロジェクト: KVSun/ad-insertion
/**
 * Lint a script and assert that it uses valid syntax
 *
 * @param  string $script The PHP script to lint
 * @return void
 */
function lint_script($script)
{
    $clean_syntax = php_check_syntax($script, $syntax_errors);
    assert($clean_syntax, $syntax_errors . __FILE__);
}
コード例 #8
0
function ValidateCode($file)
{
    return php_check_syntax($file, true);
}
コード例 #9
0
ファイル: parse_cvs.php プロジェクト: SandyS1/presentations
<?php

/* Insert into CVSROOT/commitinfo
 * DEFAULT	/path/to/php /path/to/lint.php
 */
array_shift($_SERVER['argv']);
array_shift($_SERVER['argv']);
$return_val = 0;
// loop through all files affected by commit
foreach ($_SERVER['argv'] as $val) {
    // only check PHP files
    if (strrchr($val, '.') == '.php') {
        if (php_check_syntax($val, &$err) !== TRUE) {
            echo "Error: '{$err} in '{$val}'\n";
            $return_val = 1;
        }
    }
}
// got an error, abort the commit
if ($return_val) {
    exit($return_val);
}
コード例 #10
0
ファイル: phpp.php プロジェクト: rebuy-de/nanoserv
try {
    $src = template_transform($txt, dirname($fn));
    verbose_notice("transform done");
    if (isset($options["o"])) {
        $out_fn = $options["o"];
        verbose_notice("writing destination file: '{$out_fn}'");
        file_put_contents($out_fn, $src);
        verbose_notice("done (" . number_format(strlen($src)) . " bytes)");
        if (isset($options["w"])) {
            verbose_notice("removing whitespaces");
            $bl = strlen($src);
            $src = php_strip_whitespace($out_fn);
            file_put_contents($out_fn, $src);
            verbose_notice("done (" . number_format($bl - strlen($src)) . " bytes saved)");
        }
        if (isset($options["l"])) {
            verbose_notice("checking syntax");
            $errstr = "";
            if (php_check_syntax($out_fn, $errstr)) {
                verbose_notice("syntax ok");
            } else {
                throw new Exception("syntax check failed: {$errstr}");
            }
        }
    } else {
        echo $src;
    }
} catch (Exception $e) {
    echo "error: {$e->getMessage()}\n";
    exit(-1);
}
コード例 #11
0
ファイル: display.php プロジェクト: wangshipeng/Php-Online
<?php

require_once APPLICATION_PATH . '/modules/user/parseErrors.php';
if (!isset($_GET['file']) || $_GET['file'] == '') {
    header("Location: " . $CONF["PATH_FROM_ROOT"]);
    exit;
}
$file_name = ROOT_PATH . '/code/' . $_GET['file'] . $CONF["EXTENSION"];
if (!is_file($file_name)) {
    header("Location: " . $CONF["PATH_FROM_ROOT"]);
    exit;
}
try {
    $error = php_check_syntax($file_name, true);
    if (is_array($error) && isset($error['line'])) {
        echo "Parse Error: at line no " . $error['line'] . "<br>";
        echo "Message: " . $error['msg'] . "<br>";
        exit;
    }
    $error = php_check_runtime($file_name, true);
    if (is_array($error) && isset($error['line'])) {
        echo "Error: at line no " . $error['line'] . "<br>";
        echo "Message: " . $error['method'] . " has been disabled for security reasons<br>";
        exit;
    }
    require_once $file_name;
    //echo implode(" ",$error);
} catch (Exception $e) {
    echo $message = "Error: at line no " . $e->getLine() . "<br>";
    echo $message = "Message: " . $e->getMessage() . "<br>";
}
コード例 #12
0
ファイル: mkhtml.class.php プロジェクト: h3len/Project
 public function include_file($cache_file, $data = array(), $need_page_info = array())
 {
     global $gGlobalConfig;
     $_configs = $gGlobalConfig;
     $_site = $this->site;
     $_column = $this->column;
     if ($data) {
         $m2o['data'] = $data;
     }
     if ($need_page_info) {
         $need_page_info['page_url'] = rtrim($this->weburl, '/');
         $need_page_info['page_filename'] = $this->filename;
     }
     $GLOBALS['need_page_info'] = $need_page_info;
     include_once CUR_CONF_PATH . 'data/m2o/conf/config.php';
     include_once CUR_CONF_PATH . 'data/m2o/lib/web_functions.php';
     if (php_check_syntax($cache_file, $error)) {
         ob_start();
         include $cache_file;
         $result = ob_get_contents();
         ob_clean();
     } else {
         $result = $error;
     }
     return $result;
 }
コード例 #13
0
ファイル: bridge.php プロジェクト: hasanmbstu13/wordpress
    public static function safeInclude($fileName, $constants = array(), $variables = array(), $functions = array())
    {

        if (function_exists('php_check_syntax')){
            if (!php_check_syntax($fileName)){
                return false;
            }
        }
        //TODO think about it ?!
        /*
        else {
            //http://bytes.com/topic/php/answers/538287-check-syntax-before-include
            $code = file_get_contents($fileName);
            $code = preg_replace('/(^|\?>).*?(<\?php|$)/i', '', $code);
            $f = @create_function('', $code);
            $result = !empty($f);
        }
        */
        
        if (! file_exists($fileName)){
            return false;
        }

        ob_start();
        /** @noinspection PhpIncludeInspection */
        include($fileName);
        ob_clean();

        //TODO think about moving "general" environment variables to sub-array
        $environment = array(
            'globals' => $GLOBALS,
            'session' => $_SESSION,
            'server' => $_SERVER,
            'env' => $_ENV,
            'cookie' => $_COOKIE,
            'request' => $_REQUEST,
            'get' => $_GET,
            'post' => $_POST,
            'files' => $_FILES,
            'constants' => array(),
            'variables' => array(),
            'functions' => array()
        );

        $constantsValues = array();
        foreach($constants as $constantName){
            if (defined($constantName)){
                $constantsValues[$constantName] = constant($constantName);
            }
            else {
                $constantsValues[$constantName] = null;
            }
        }
        $environment['constants'] = $constantsValues;

        $variablesValues = array();
        foreach($variables as $variableName){
            $variablesValues[$variableName] = $$variableName;
        }
        $environment['variables'] = $variablesValues;

        $functionsCallbacks = array();
        foreach($functions as $functionName){
            if (function_exists($functionName)){
                $functionsCallbacks[$functionName] = $functionName;
            }
        }
        $environment['functions'] = $functionsCallbacks;
        $environment['general'] = array();
        $environment['general']['bufferCount'] = ob_get_level();
        return $environment;
    }
コード例 #14
0
ファイル: HtmlHaml.php プロジェクト: athem/athem
 /**
  * @param string $path
  * @throws \Athem\Code\Exception\CompileError
  */
 protected function phpSyntaxCheck($path)
 {
     try {
         $return = 0;
         $this->systemCall('ls', $return);
         ob_start();
         system("/usr/bin/php -l {$path} 2>&1");
         $result = ob_get_clean();
         $count = 0;
         $syntaxError = preg_replace("/Errors parsing.*\$/", "----------------", $result, -1, $count);
         if ($count > 0) {
             throw new Code\Exception\CompileError($result);
         }
     } catch (\Exception $e) {
         if ($e instanceof Code\Exception\CompileError) {
             throw $e;
         }
         // http://php.net/manual/en/function.php-check-syntax.php
         if (function_exists('php_check_syntax')) {
             $errorMessage = '';
             if (!php_check_syntax($path, $errorMessage)) {
                 throw new Code\Exception\CompileError($errorMessage);
             }
         } else {
             // TODO: Until further documentation, it 'system' is not enabled
             // and php_check_syntax does not exist there is no way of
             // checking php syntax.
         }
     }
 }