草庐IT

protected

全部标签

php - 创建可折叠 print_r() var_dump() 的函数?

您可能熟悉print_r的输出:HierarchyObject([parent:private]=>HierarchyObject([parent:private]=>[children:private]=>Array()[level:private]=>0[price_modes:private]=>Array()[id:protected]=>[left_id:protected]=>[right_id:protected]=>[name:protected]=>[validationFailures:protected]=>Array()[_new:private]=>1[_de

php - 如何使用正则表达式从数组中找到匹配的键

当我打印我的Joomlasession时,我得到如下所示的数组输出。现在我想找到compare_session并且所有带有此键的mtaching都需要用逗号分开存储。我不会在数组中使用重复键。我想要这样的输出:281,147,136,96,46,30Array([__default]=>Array([session.counter]=>9[session.timer.start]=>1376717892[session.timer.last]=>1376718229[session.timer.now]=>1376718247[session.client.browser]=>Mozi

php - 从父类访问子变量?

我该怎么做?classtest{publicstaticfunctionrun(){echo"Numberis:".$num;}}classtestchildextendstest{protectedstatic$num=5;publicstaticfunctionexec(){$num=5;parent::run();}}testchild::exec();表示undefinedvariable“num”。http://ideone.com/WM7tHk如何访问这个变量? 最佳答案 你不应该这样做,因为你要求parent访问它可能

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、Yii 用户扩展

我尝试安装yii扩展http://www.yiiframework.com/extension/yii-user/并尝试插入命令“yiicmigrate--migrationPath=user.migrations”。如何正确地做到这一点,而不是:C:\xampp\htdocs\eshops\protected>..\framework\yiicmigrate--migrationPath=modules.user.migrationsError:Themigrationdirectorydoesnotexist:modules.user.migrationsC:\xampp\htdo

php - 如何使学说支持时间戳列?

我正在尝试应用以下迁移:Schema::table('users',function(Blueprint$table){$table->timestamp('created_at')->useCurrent()->change();});但是artisan说:[Doctrine\DBAL\DBALException]Unknowncolumntype"timestamp"requested.AnyDoctrinetypethatyouusehastoberegisteredwith\Doctrine\DBAL\Types\Type::addType().Youcangetalistof

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 - symfony 验证另一个字段是否为特定值

如果另一个字段(3)是选项“a”,我正在尝试编写一个字段(1)的验证,如果3是“b”,则需要另一个字段(2)。我该怎么做?编辑:它适用于实体。我将发布我正在尝试的示例。/***@Assert\Collection(*fields={aName=@Assert\NotBlank(),*aAmount=@Assert\NotBlank()}*/protected$1;/***@Assert\Collection(*fields={bName=@Assert\NotBlank(),*bAmount=@Assert\NotBlank()}*/protected$2;/***@Assert\No

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))