700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 报个错Parse error: syntax error unexpected ‘static’ (T_STATIC)

报个错Parse error: syntax error unexpected ‘static’ (T_STATIC)

时间:2020-11-03 00:50:46

相关推荐

报个错Parse error: syntax error  unexpected ‘static’ (T_STATIC)

后端开发|php教程

报个错Parse error: syntax error, unexpected ‘static’ (T_STATIC)

后端开发-php教程

网页装饰源码,ubuntu的nat模式,tomcat连接池空闲回收,爬虫方案论证,php列表写上一页,安阳seo营销lzw

title = $title; $this->producerMainName = $mainName; $this->producerFirstName = $firstName; $this->price = $price; } function setDiscount($num){ $this->discount = $num; } function getDiscount(){ return $this->discount; } function getTitle(){ return $this->title; } function getProducerFirstName(){ return $this->producerFirstName; } function getProducerMainName(){ return $this->producerMainName; } function getId(){ return $this->id; } function setId($id){ $this->id = $id; } function static getInstance($id,PDO $pdo){ $stmt = $pdo->prepare("select * from products_4 where id =?"); $result = $stmt->execute(array($id)); $row = $stmt->fetch(); if(empty($row)){ return null; }if($row[ ype]==ook){$product = new BookProduct( $row[ itle],$row[firstname],$row[mainname],$row[price],$row[ umpages]); } elseif($row[ ype]==cd) { $product = new CdProduct( $row[ itle],$row[firstname],$row[mainname],$row[price],$row[playlength]); } else{$product = new ShopProduct( $row[ itle],$row[firstname],$row[mainname],$row[price]); }$product->setId($row[id]); $product->getDiscount($row[discount]); return $product; } function getPrice(){ return "({$this->price} - {$this->discount})"; } function getProducer(){ return "{$this->producerFirstName}". " {$this->producerMainName}"; } function getSummaryLine(){ $base = "{$this->title} ( {$this->producerMainName}"; $base .= " {$this->producerFirstName} )"; return $base; }}class CdProduct extends ShopProduct{ private $playLength = 0; function __construct($title,$firstName,$mainName,$price,$playLength){ parent::__construct($title,$firstName,$mainName,$price); $this->playLength = $playLength; } function getSummaryLine(){$base = parent::getSummaryLine();$base .= ": playing - time {$this->playLength}";return $base; }}class BookProduct extends ShopProduct{ private $numPages = 0 ; function __construct($title,$firstName,$mainName,$price,$numPages){ parent::__construct($title,$firstName,$mainName,$price); $this->numPages = $numPages; } function getNumPages(){ return $this->numPages; } function getSummaryLine(){ $base = parent::getSummaryLine(); $base .= ": page count - {$this->numPages}"; return $base;} function getPrice(){ return $this->price; }}$dsn = "mysql:host=localhost;dbname=test";try{ $pdo = new PDO($dsn,"root","root"); $pdo->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION); $obj = ShopProduct::getInstance(1,$pdo);}catch(PDOException $e){ echo $e->getMessage();}print_r($obj);

Parse error: syntax error, unexpected ‘static’ (T_STATIC), expecting identifier (T_STRING) in D:\Apache24\htdocs\PHP_OBJECT\4\4.1.2.php on line 46

function static getInstance 静态变量为什么这样写报错呢? static function 这样就可以输出数据?

asp 源码 鲜花,更改VSCode图标,ubuntu服务器网卡调试,tomcat手机安装,微信文件sqlite,手机相册小插件下载安装,原生app前端开发框架,python爬虫怎么入门,php图片 图片服务器,seo竞价和优化seo教程,小说app网站源码,网页面包屑,phpcms 图库 模板,js 上下页本页面翻页,mac客户管理系统,动漫视频模板程序lzw

回复讨论(解决方案)

员工注册源码,ubuntu搭建游戏环境,java爬虫单点登录,php常用函数学习方法交流教程,凤城seo公司lzw

function static 写反了,应为

static function

function static 写反了,应为

static function

这个在php文档上有写吗?

可能有吧,这是常识!

static function getInstance($id,PDO $pdo){

static 是修饰 function 的,是说名为 getInstance 的 function 是静态的

而你写成 function static getInstance($id,PDO $pdo){ 的话

且不说 static 的位置不对

function 后面应该是函数名,难不成就是 static getInstance ?

函数名也不能拆成两段呀,这不合语法

可能有吧,这是常识!

static function getInstance($id,PDO $pdo){

static 是修饰 function 的,是说名为 getInstance 的 function 是静态的

而你写成 function static getInstance($id,PDO $pdo){ 的话

且不说 static 的位置不对

function 后面应该是函数名,难不成就是 static getInstance ?

函数名也不能拆成两段呀,这不合语法

class StaticExample{

public static $aNum = 0 ;

private static function sayHello(){ // private static 和static private两样排序都可以??

self::$aNum++;

print ‘hello (‘.self::$aNum.’)’;

}

function getSayHello(){

self::sayHello();

}

}

StaticExample::$aNum;

$staticExample = new StaticExample();

$staticExample->getSayHello();

但是这样没有报错,php版本是5.4.32的

看错了,谢谢您。结账。

function static getInstance 改为 static function getInstance

static是修饰符,按语法规则需要写在被修饰的变量或方法前面。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。