草庐IT

b-Class-Interface

全部标签

php - 使用带有常量的接口(interface)作为类的多态行为的开始是好的做法吗?

StackOverflow上的一些人认为这可能是一个好的实现吗?例如,我有一个名为RequestInterface的接口(interface),它有5个常量:interfaceRequestInterface{constGET=1;constPOST=2;constPUT=3;constDELETE=4;constHEAD=5;publicfunctiongetType();//...someothermethodsdeclarations}然后对于每个常量一个实现该接口(interface)的类,例如PostRequest:classPostRequestimplementsRequ

PHP 5.5 : accessing a static class member of a dynamic class stored in an object

我们假设如下:classa{publicstatic$foo='bar';}classb{public$classname='a';}$b=newb();是否可以通过某种方式(大括号等)直接访问$foo而不会生成“意外的::(T_PAAMAYIM_NEKUDOTAYIM)”:$b->classname::$foo//shouldresultin"bar"notinan"unexpected::(T_PAAMAYIM_NEKUDOTAYIM)"我知道并使用以下解决方法:$c=$b->classname;$c::$foo;但我想知道是否存在另一种直接访问$foo的好方法。

php - Laravel 解析错误 : syntax error, unexpected T_CLASS, expecting T_STRING

我在今年8月开发了一个laravel应用程序,当时它运行良好。我现在正在尝试运行该应用程序,但它返回了这个错误:parseerror:syntaxerror,unexpectedT_CLASS,expectingT_STRINGorT_VARIABLEor'{'or'$'inD:\bkonme\artisanline31第31行是这样的:$kernel=$app->make(Illuminate\Contracts\Console\Kernel::class);我的PHP版本是5.6.14,我在windows平台上使用XAMPP。我有一些想法,因为laravel和PHP之间存在一些版本

php - 如何在 Laravel 5.1 中观察所有实现接口(interface)的模型?

我有一个扩展Eloquent模型的审计类...classAuditextendsModel{}我有一个可审核的界面...interfaceIAuditiable{publicfunctionaudit();}我有一个特性可以实现接口(interface)并定义模型和审计之间的关系...traitAuditable{publicfunctionaudit(){return$this->hasMany('Audit');}}我有一个扩展Eloquent模型的模型,它实现了接口(interface)并使用了特征...classPostextendsModelimplementsIAudita

php - 为什么我会收到此错误 : Class "Google_Service_Calendar" not found?

这是我的代码:这只是来自GoogleDevelopers的示例Quickstart.php:require__DIR__.'/vendor/autoload.php';define('APPLICATION_NAME','GoogleCalendarAPIPHPQuickstart');define('CREDENTIALS_PATH','~/.credentials/calendar-php-quickstart.json');define('CLIENT_SECRET_PATH',__DIR__.'/client_secret.json');define('SCOPES',impl

php - Symfony 3.3 从 3.2 : Compile Error: Cannot declare class Symfony\Bundle\SecurityBundle\Security\FirewallMap

自从我从symfony3.2更新到3.3后我遇到了一些问题,我得到了这个错误CompileError:CannotdeclareclassSymfony\Bundle\SecurityBundle\Security\FirewallMap,becausethenameisalreadyinuseinclasses.php(line1709)inClassCollectionLoader.php(line99)atClassCollectionLoader::load()inKernel.php(line428)atKernel->doLoadClassCache()inKernel.p

php - "Fatal error: Cannot redeclare class"...但是类没有声明

(我使用的是Joomlav1.5.15和PHP5.3.4)我已经测试了在这个和其他开发者论坛中找到的解决方案,但我仍然遇到同样的错误。需要文件=>contratolocal.php...if(!class_exists('MTIHelperEstadosLocal'))JLoader::import('helpers.estados.estadoslocal',JPATH_COMPONENT,false);classMTIControllerContratoLocalextendsMTIController{...所需文件=>estadoslocal.php...classMTIHel

PHP - 关联数组 : Changing keys for key value pair where value is a class object

我有一个形式的关联数组:$input=array("one"=>,"two"=>$input的键保证是唯一的。我还有一个名为moveToHead($key)的方法,它将$input[$key]元素移动到此关联数组的第0个位置。我有几个问题:是否可以确定关联数组的索引?如何将对应的$key=>$value对的数组条目移动到索引0并保留$key原样?实现上述两点的最佳方法是什么?我想为第二点做array_flip(子解决方案),但后来发现array_flip只能在数组元素为int和string时完成。有什么指点吗? 最佳答案 使用名为a

php - 未找到 Zend Framework 2.0 接口(interface)

精简版Client类在哪里寻找DispatchableInterface接口(interface)?classClientimplementsLibraries\Stdlib\DispatchableInterface我正在尝试将ZF2库添加到CodeIgniter安装中。整个Zend文件夹位于:/Users/stef/Sites/site_name/application/libraries/在我的CIController中我有publicfunctionrun(){$CI=&get_instance();$CI->load->library('Zend');$CI->load->l

PHP 面向对象 : Get all declared classes which are have extended another parent class

我需要获取所有扩展了另一个父类的声明类。例如……classParentClass{}classChildOneextendsParentClass{}classChildTwoextendsParentClass{}classChildThree{}我需要一个输出这个的数组:array('ChildOne','ChildTwo')我是PHPOOP的新手,但基于一些谷歌搜索,我想到了这个解决方案。$classes=array();foreach(get_declared_classes()as$class){if(is_subclass_of($class,'ParentClass'))