很抱歉,上下文太模糊,但这个问题非常模糊。到目前为止,我将尝试传达这些经验。
这是我正在编辑的代码,它位于第133行:
$log->log('info', 'total_data: ' . count( $result->data ) );
上面的代码工作正常,当我将字符串更改为'total_results'时,它导致语法错误:
$log->log('info', 'total_results: ' . count( $result->data ) );
只要有任何字符发生变化,错误就会随机变化。例如,上面的代码犯了这个错误
Parse error: syntax error, unexpected ']' in /web/api.php on line 180
仅供参考:此档案中只有179行。
如果我从字符串中删除一个字母:
$log->log('info', 'total_result: ' . count( $result->data ) );
以上错误更改为:
Parse error: syntax error, unexpected ']' in /web/api.php on line 181
如果我一次删除一个字母并刷新行号会不断增加。
有时候如果我删除该行,保存,刷新,粘贴回来,保存,刷新它就可以了。有时,如果我在字符串中添加更多字符,它将起作用。这必须是超出语法错误的级别,因为相同的代码将在以后工作。我试图重新启动apache2但是没有修复任何东西,它通常会显示一个不同的随机错误。我看不出与错误消息的任何一致性。一致的事情似乎是,只要没有任何改变,错误就会保持不变。
以下是我在尝试查找某些一致性时看到的其他错误消息:
Parse error: syntax error, unexpected 'DirectMap4k' (T_STRING) in /web/api.php on line 180
我再次删除了一行,保存,刷新,放回该行,保存,刷新然后就可以了。
的logging.php
<?php
class logger {
protected $file = null;
protected $log_level = 3;
protected $_date_fmt = 'Y-m-d H:i:s.u';
protected $_levels = [ 'CRITICAL' => 0,
'ERROR' => 1,
'WARNING' => 2,
'INFO' => 3,
'DEBUG' => 4,
'TRACE' => 5,
'TRACE1' => 6,
'TRACE2' => 7 ];
function __construct( $name = 'Anonymous',
$file = 'application.log' )
{
$this->name = $name;
$this->filename = $file;
// check if file exists before fopen creates the file
$new_file = ! file_exists( $file );
// die if file is not writable
if( ! ( $new_file or is_writable( $file ) )) {
die( "logger class cannot write to file: <b>" . $file . "</b>" );
}
$this->file = fopen( $file, 'a' );
if( $new_file ) {
$this->write( "<"."?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?".">\n\n" );
}
}
public function log( $level, $message )
{
if( $this->_levels[ strtoupper( $level ) ] > $this->log_level ) {
// do not log
return;
}
list( $usec, $sec ) = explode( ' ', microtime() );
$datetime = sprintf( '%s.%03d',
date("Y-m-d H:i:s", $sec),
floor($usec * 1000) );
$write = sprintf( '%s - %8.8s : %s',
$datetime,
strtolower( $level ),
$message );
$this->write( $write . "\n" );
}
private function write( $message )
{
fwrite( $this->file, $message );
}
function __destruct()
{
if( $this->file ) {
fclose( $this->file );
}
}
}
?>
答案 0 :(得分:0)
问题最终是使用HGFS进行Vagrant文件同步。这些文件实际上在主机上,并且它们没有准确同步。为了避免随机错误,我决定永远不要在HGFS上共享开发代码。