草庐IT

settings

全部标签

php - __set 和 __get 方法在类内外的行为是否不同?

我正在研究PHP中的OOP,并尝试编写一个基本的Session类,它将创建一个Session数组。在实例化类时,用户将提供数组的第一维,然后我希望他们能够向该session添加任何变量/值组合。例如:$session=newMy_Session('testing');$session->boy='girl';应该等同于输入$_SESSION['testing']['boy']='girl';我以为我可以使用PHP神奇的__set和__get方法,但我的输出不是预期的。下面是我的类(class)、示例和结果:类:classMy_Session{function__construct($s

php - Zend 框架 2 : Set options as "selected" in select list

我正在尝试将第二个产品设置为在列表中选中,但下面的代码不起作用。任何的想法。谢谢$this->add(array('type'=>'Zend\Form\Element\Select','name'=>'manufacturer','options'=>array('label'=>'Manufacturername','value_options'=>$this->getManufacturer(),'empty_option'=>'---selectmanufacturer---',),'attributes'=>array('value'=>2,'selected'=>true,)

编辑配置文件的PHP函数

我正在寻找可用于编辑文本文件中的键/值对的PHP函数。我想做什么(PHP):changeValue(key,bar);并在setings.txt中:key=fookey2=foo2更改为:key=barkey2=foo2到目前为止我得到了什么(不工作):functionchangeValue($input){$file=file_get_contents('/path/to/settings.txt');preg_match('/\b$input[0]\b/',$file,$matches);$file=str_replace($matches[1],$input,$file);fil

使用变量中的数字和运算符进行 PHP 计算

这个问题在这里已经有了答案:PHPparse/syntaxerrors;andhowtosolvethem(20个答案)关闭6年前。我已经在PHP中设置了这些变量:$settings["operator"]='/';$settings["figure"]='0.6';然后我想在另一个变量上使用上面的内容来计算,最终将是:$total=($var->price/0.6);我试过这个:$total=($var->price$settings["operator"]$settings["figure"]);但是我得到一个错误,因为代码不正确:Parseerror:syntaxerror,un

php - 使用 ini_set() 的 PSR-1 兼容替代方案是什么?

我正在使我的代码库符合PSR-2标准(因此符合PSR-1标准),我遇到了以下代码:publicfunctioninit(){parent::init();//AllowALargerPHPMemoryLimitForThisScriptini_set("memory_limit","512M");//AllowALargerScriptExecutionLimitForThisScriptini_set('max_execution_time',300);}用于增加此特定脚本(仅供站点管理员访问且不经常运行)能够消耗的内存量和执行时间。在php.ini中设置默认的memory_limi

php - 在 laravel 中全局缓存表值

我有一个表:设置模型SettingclassSettingextendsModel{protected$fillable=['name','value',];}我已经创建了一个服务提供SettingsServiceProvider并在app.php中注册了classSettingsServiceProviderextendsServiceProvider{/***Bootstraptheapplicationservices.**@returnvoid*/publicfunctionboot(Factory$cache,Setting$settings){if(\Schema::has

php - codeception : Setting the "doctrine" pre-defined service is deprecated since Symfony 3. 3 并且 Symfony 4.0 将不再支持

我的项目是一个带有DoctrineORM的Symfony3.3.9项目。我将codeception2.3.6与模块Doctrine2一起使用,我关注这篇文章:http://codeception.com/docs/modules/Doctrine2我的codeception配置是:#tests/functional.suite.ymlactor:FunctionalTestermodules:enabled:-\Helper\Functional-PhpBrowser:url:http://localhost-Symfony-Doctrine2:depends:Symfonyclean

php - __get() 和 __set() 的最佳实践

按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visitthehelpcenter指导。关闭10年前。源于此question关于使用__get()和__set()访问私有(private)变量,我想了解一下它们的一般使用方式。我想知道何时何地是使用重载函数的最佳时机,以及您在哪里使用过重载函数(如果有的话)。为了清楚起见,我们正在谈论这些功能:http://us2.php.net/manual/en/language.oop5.magic.php

php __get() 和 __set() 魔术的要点

PHP5引入了魔术方法__get()和__set()。根据我的理解,这是必须编写每个成员的getter和setter的捷径;$var=$name;}function__get($var){return$this->$var;}}$person=newPerson();$person->firstname="Tom";$person->lastname="Brady";echo$person->firstname."".$person->lastname;//print:TomBrady?>我的问题是,这就像公开成员变量一样。classPerson{public$firstname;pu

php - Zend_Cache - "Datas must be string or set automatic_serialization = true"

我正在尝试像这样使用Zend_Cache缓存一个数组:$cache=Zend_Registry::get('cache');//$dataisanarray$cache->save($data,'externalData');我收到这个错误:Message:Datasmustbestringorsetautomatic_serialization=true即使在引导文件中初始化Zend_Cache时automatic_serialization设置为真:protectedfunction_initCache(){$frontend=array('lifetime'=>7200,'aut