类可以扩展PHP中的接口和另一个类吗?
基本上我想这样做:
interface databaseInterface{
public function query($q);
public function escape($s);
//more methods
}
class database{ //extends both mysqli and implements databaseInterface
//etc.
}
Run Code Online (Sandbox Code Playgroud)
如何做到这一点,只需做:
class database implements databaseInterface extends mysqli{
Run Code Online (Sandbox Code Playgroud)
导致致命错误:
Parse error: syntax error, unexpected T_EXTENDS, expecting '{' in *file* on line *line*
我有一个文件包含一个名为sitemap.html和在站点地图中的文件,我有以下代码:
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">
<url>
<loc><?php echo SITE_URL . '/'; ?></loc>
<changefreq>monthly</changefreq>
<priority>1.00</priority>
</url>
<?php foreach ($this->data->content as $content): ?>
<url>
<loc><?php echo SITE_URL . $content->permalink; ?></loc>
<lastmod><?php echo date("Y-m-d", $content->publish_date); ?></lastmod>
<changefreq>monthly</changefreq>
<priority><?php echo $content->sitemap_index; ?></priority>
</url>
<?php endforeach; ?>
</urlset>
Run Code Online (Sandbox Code Playgroud)
一切似乎都没问题,但我收到的错误500就是说:
PHP解析错误:语法错误,第1行的sitemap.html中的意外"版本"(T_STRING)
正如你所看到的,我正在使用<?xml而不是<?php为什么它试图将其解析为PHP?
起初,我认为这是导致问题的神奇引号,但是当我执行get_magic_quotes_gpc()的var_dump时,我得到bool(false)了神奇的引号甚至都没有.
此外,在我的php.ini,我看到magic_quotes的OFF.
作为修复它的替代方法,我用以下内容替换了我的第一行:
<?php echo '<?xml version="1.0" encoding="UTF-8"?>'; ?>
Run Code Online (Sandbox Code Playgroud)
但我仍然对正在发生的事感到好奇.
我有其他网站托管在同一台服务器上(PHP版本5.4.45),我没有在其他网站的站点地图上得到PHP Parse Error ... …
我得到一个错误说
解析错误:语法错误,第6行的E:\ PortableApps\xampp\htdocs\SN\AC\ACclass.php中的意外T_PRIVATE
在尝试运行我的脚本时.我是PHP的新手,想知道是否有人可以指出我的错误.这是该部分的代码.
<?php
class ac
{
public function authentication()
{
private $plain_username = $_POST['username'];
private $md5_password = md5($_POST['password']);
$ac = new ac();
Run Code Online (Sandbox Code Playgroud) 我有一个小问题.我目前在000webhost上有我的网站,并且以下行:
$price = explode(".",$item->sellingStatus->currentPrice)[0];
Run Code Online (Sandbox Code Playgroud)
导致以下错误:
解析错误:语法错误,第58行/home/a1257018/public_html/scripts/myfile.php中的意外'['
当它在localhost上没有引起这种情况时.代码应该工作... explode返回一个数组,[0]只需调用第一个项目.为什么这会引发错误?
当我使用作曲家安装Laravel 5时,我收到此错误:
不能使用"PhpParser \节点\标\字符串"作为类名称,因为它是在/Applications/XAMPP/xamppfiles/htdocs/learnlaravel5/vendor/nikic/php-parser/lib/PhpParser/PrettyPrinter/Standard.php保留上线86
怎么了?
请问,以下代码有什么问题?什么是正确的方法呢?
class SomeClass {
var $someVar = trim('some value');
}
Run Code Online (Sandbox Code Playgroud)
我得到的错误:
PHP解析错误:语法错误,意外'(',期待','或';'在第3行的/tmp/testik.php中
非常感谢你.
public function getUserRoles()
{
public $query = "SELECT * FROM user_roles WHERE userID = ".floatval($this->userID)."ORDER BY addDate ASC";
if ($query_run = mysql_query($query))
{
public $resp = array();
while ($query_row = mysql_fetch_array($query_run))
{
$roleID = $query_row['roleID'];
}
return $resp;
}
}
Run Code Online (Sandbox Code Playgroud)
我收到错误:解析错误:语法错误,第34行/Applications/XAMPP/xamppfiles/htdocs/acltut/assets/php/class.acl.php中的意外T_PUBLIC.在这种情况下,第34行将是第3行它说"公共$查询".
不应该给变量赋予"可见性"或"权限",如var/public/private/protected/etc.
如果是这种情况,那么下一行不一定要写成:
if (public $query_run = mysql_query($this->query)) {}
Run Code Online (Sandbox Code Playgroud)
我很困惑你何时必须包含public/private/protected并使用$ this->引用变量以及何时可以创建变量.
任何人都可以帮我调试这个问题吗?这是我想从cron运行的php脚本的一部分.我一直在看它,但无法弄清楚出了什么问题.以下行抛出PHP错误"PHP Parse错误:语法错误,意外的T_LNUMBER在......行..."
$sqlreadstmt = $db->query("
select distinct
rsdata.rs_variant,
rsdata.weeknumber,
rsdata.rs_moduleid,
rsdata.rs_objectidentifier,
trdata.tr_objectidentifier,
trdata.tr_testversion,
trdata.tr_plannedgate,
trdata.tr_vnvmethod,
testatussequence.tesequencenr,
trdata.tr_testexecutionstatus
from rsdata,trdata,module,variantgates,testatussequence
where rsdata.weeknumber="1339"
and rsdata.rs_moduleid = module.moduleid
and rsdata.weeknumber = trdata.weeknumber
and rsdata.rs_reviewstatus != "Obsolete"
and rsdata.rs_reviewstatus != "Rejected"
and rsdata.rs_introbjectidentifieralllevels != ""
and rsdata.rs_introbjectidentifieralllevels != "Unknown"
and find_in_set(trdata.tr_objectidentifier, (select rsdata.rs_introbjectidentifieralllevels))
and trdata.tr_plannedgate != ""
and trdata.tr_plannedgate != "Unknown"
and trdata.tr_plannedgate = variantgates.gate
and trdata.tr_variant = variantgates.variant
and trdata.tr_testexecutionstatus = testatussequence.testatus
order by
rs_variant ASC,
weeknumber ASC,
rs_moduleid ASC,
rs_objectidentifier ASC,
tr_testversion …Run Code Online (Sandbox Code Playgroud) 我有三个按钮,编辑删除和视图..在视图部分我试图回显行ID,以获取详细信息.但我得到这个解析错误.
这是代码:
while( $row=mysqli_fetch_array($query) ) {
$active = '';
if($row['active'] == 1) {
$active = '<label class="label label-success">Complete</label>';
} else {
$active = '<label class="label label-danger">Incomplete</label>';
}
$actionButton = '
<div class="btn-group">
<button type="button" class="btn btn-default dropdown-toggle" data- toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Action <span class="caret"></span>
</button>
<ul class="dropdown-menu">
<li><a type="button" data-toggle="modal" data-backdrop="static" data-keyboard="false" data-target="#editMemberModal" onclick="editMember('.$row['id'].')"> <span class="glyphicon glyphicon-edit"></span> Edit</a></li>
<li><a type="button" data-toggle="modal" data-target="#removeMemberModal" onclick="removeMember('.$row['id'].')"> <span class="glyphicon glyphicon-trash"></span> Remove</a></li>
<li><a class="view_data" type="button" data-toggle="modal" data-target="#dataModal" id="'.<?php echo $row['id']; ?>.'"><span class="glyphicon glyphicon-trash"></span> View</a></li>
</ul> …Run Code Online (Sandbox Code Playgroud) 我在定义函数和从 error_reporting(E_ALL);
有错误 Parse error: syntax error, unexpected ',', expecting variable (T_VARIABLE) in C:\xampp\htdocs\bs4\func.php on line 4
这是我的代码
<?php
error_reporting(E_ALL);
require_once "condb.php";
function noproblem(time,suggest,phone,eat,problem){ // Here is line 4
$sql="insert into data(time,suggest,phone,eat,problem) values(?,?,?,?,?)";
$stmt=$cn->prepare($sql);
$stmt->bindParam("1",time);
$stmt->bindParam("2",suggest);
$stmt->bindParam("3",phone);
$stmt->bindParam("4",eat);
$stmt->bindParam("5",problem);
try {
$stmt->execute();
echo "ok!";
} catch (Exception $e) {
echo $e->getTraceAsString();
}
}
?>
Run Code Online (Sandbox Code Playgroud) php-parse-error ×10
php ×9
arrays ×1
composer-php ×1
html ×1
laravel-5 ×1
parsing ×1
pdo ×1
sql ×1
syntax-error ×1