草庐IT

general-protection-fault

全部标签

php - php父类(super class)如何访问其子类的 protected 方法?

我今天才注意到这种行为-很奇怪,我很确定在java中你只能访问继承链上游的protected方法,因为另一种方式违反了封装。语言中有这种行为的原因吗? 最佳答案 我发现当在父类中定义的一个方法只需要根据扩展类类型更改其功能的一小部分时,它很有用。您可以从父类中调用抽象方法,并且它的功能会根据需要随着子类中该方法的定义而改变。我还要补充一点,兄弟类也可以访问彼此的protected属性和方法,只要它们在父类中声明(可以是抽象的也可以不是)。 关于php-php父类(superclass)如

php - 为什么变量应该有 public 或 private 或 protect 但函数不应该在类中

我知道为什么我不能在没有任何东西的情况下在类中定义变量吗?(公共(public)、私有(private)、保护)为什么这有语法错误?classmyclass{$var='anythig';}但这没关系:classmyclass{functiontest(){//codehere}}最后,为什么我可以定义一个没有任何功能的var?classmyclass{functiontest(){$var='anything';//ithasnotanythig(public,privare,protect)}} 最佳答案 当你使用任何编程语言时

php - Laravel/无法访问 protected 属性 Illuminate\Database\Eloquent\Collection::$items

我仍在学习Laravel,我正在使用Eloquent来运行我的查询。在我的应用程序中,一个用户可以属于一个圈子。圆圈包含存储库,存储库又包含项目。我正在尝试获取一个圈内属于各种存储库的所有项目。用户模型:publicfunctioncircle(){return$this->belongsTo('App\Models\Circle');}圆形模型:publicfunctionusers(){return$this->hasMany('App\Models\User');}publicfunctionrepositories(){return$this->hasMany('App\Mod

php - SQLite3,SQLSTATE[HY000] : General error: 5 database is locked

我有这个小测试脚本:session_start();session_write_close();error_reporting(-1);register_shutdown_function(function(){//echo'shutdown';});$MAX=120;set_time_limit($MAX);echodate('Y-m-dH:i:s').'';$m=microtime(true);$file_db=newPDO('sqlite:'.dirname(__FILE__).'/test.sqlite3');$file_db->setAttribute(PDO::ATTR_E

php - SQLSTATE[HY000] : General error: 2053 error occurs at Laravel

首先,我的环境是LAMP(M代表MariaDB)。整个错误是:SQLSTATE[HY000]:Generalerror:2053(SQL:UPDATEDemosSETHit=ifnull(Hit,0)+1WHEREid='27')模型中的代码是protectedfunctionIncreaseHit($id){DB::select('UPDATEDemosSETHit=ifnull(Hit,0)+1WHEREid=\''.$id.'\'');}我想说的是这段代码在我的本地运行良好。(本地环境是MAMP。)在Controller中调用上述模型方法的代码是if(Cookie::get('M

php - 找出一个方法是 protected 还是公共(public)的

使用这段代码,我试图测试我是否可以调用某些函数if(method_exists($this,$method))$this->$method();但是现在我希望能够在$methodprotected情况下限制执行,我需要做什么? 最佳答案 您需要使用Reflection.classFoo{publicfunctionbar(){}protectedfunctionbaz(){}privatefunctionqux(){}}$f=newFoo();$f_reflect=newReflectionObject($f);foreach($f

php - 如何取消设置/删除 protected 属性(property)

我有一个产品对象/类如下:classProduct{/***@ORM\Id*@ORM\Column(type="integer")*@ORM\GeneratedValue(strategy="AUTO")*/protected$id;/***@Exclude()*@ORM\Column(name="deletedAt",type="datetime",nullable=true)*/private$deletedAt;/***@Assert\NotBlank()*@Assert\MinLength(limit=3,message="ProductNameshouldhaveatleas

php - 获取 protected 对象中的字符串

我正在尝试获取此对象中的字符串“thisinfo”,我们称它为$object,但数据是protected,我如何访问该数据包?object(something)#29(1){["_data":protected]=>array(10){["Id"]=>array(1){[0]=>string(8)"thisinfo"}["SyncToken"]=>array(1){[0]=>string(1)"0"}["MetaData"]=>array(1){显然$object->_data给我一个错误无法访问protected属性 最佳答案 有

php - 在方法中声明 protected 变量

我仔细看了看,似乎找不到这个问题的答案。基本上,我使用_call方法动态生成get和set方法,但是在声明变量时,PHP的默认值是公开的。无论如何要将类中的变量声明为protected?function__call($method,$arguments){$prefix=strtolower(substr($method,0,3));$property=strtolower(substr($method,3));if(empty($prefix)||empty($property)){return;}if($prefix=="get"&&isset($this->$property))

php - 如何检测类属性是私有(private)的还是 protected

如何不使用外部库(仅限纯PHP)检测类属性是私有(private)的还是protected?如何检查是否可以从类外部设置属性? 最佳答案 使用Reflection.getProperty('foo');var_dump($prop->isPrivate());$prop=$reflector->getProperty('bar');var_dump($prop->isPrivate());?> 关于php-如何检测类属性是私有(private)的还是protected,我们在StackO