草庐IT

static-initializer

全部标签

PHP 类 : assigning static property via constructor

类的简化示例:classTableextendsTableAbstract{protectedstatic$tablename;function__construct($str){$this->tablename="table_".$str;$this->insert();//abstractfunction}}当我过去使用这样的类时,我在编写类时直接分配了$tablename。但是这次我希望它由构造函数决定。但是当我调用引用$tablename的函数时,当我回显SQL时,变量似乎是空的。我做错了什么,或者有人可以建议一种方法来实现我在这里想要的吗?感谢您的任何评论/回答..

php - 更新 : Best practices for managing static content in Zend Framework?

我有一些关于Zend框架的问题。我正在尝试使用现在默认的displayAction()方法通过默认Controller路由所有静态页面。目的是让displayAction()通过查看page参数来处理请求,确定脚本页面是否存在,如果它确实呈现View,否则抛出404找不到页面错误。此外,还会进行测试以查看是否存在与参数同名的方法,如果存在,则调用该操作。此处列出的是来自application.ini的路由配置resources.router.routes.static-pages.route=/:pageresources.router.routes.static-pages.defa

php - 位于 'reading initial communication packet' 的 MySQL 服务器,系统错误 : 111

关闭。这个问题不符合StackOverflowguidelines.它目前不接受答案。这个问题似乎不是关于aspecificprogrammingproblem,asoftwarealgorithm,orsoftwaretoolsprimarilyusedbyprogrammers的.如果您认为这个问题是关于anotherStackExchangesite的主题,您可以发表评论,说明问题可能在哪里得到解答。关闭6年前。Improvethisquestion我将我的站点移至godaddy服务器,但即使进行了充分的更改,SQL连接仍无法正常工作,而之前工作得很好ACTIVE";?>显示错误

php - fatal error : Non-static method in PHP using PDO for MySQL

我正在使用PDO向表中插入一行,我需要新行的ID,以便我可以根据该行重定向到新页面。当我使用$id=PDO::lastInsertId();我明白了Fatalerror:Non-staticmethodPDO::lastInsertId()cannotbecalledstaticallyinC:\xampp\htdocs\createimage.phponline16这是导致错误的php:prepare('INSERTINTOimages(id,link,title,caption)VALUES(NULL,:link,:title,:caption)');$stmt->execute(

php - 区别 static::class vs get_called_class() 和 __CLASS__ vs get_class() vs self::class

我见过几个线程,人们在其中询问如何在PHP中获取类或对象的名称。但是,我在任何地方都看不到所解释的各种可能性之间的区别。我希望这里有人可以帮助我。所以为了得到被调用类的类名,我知道两种可能:get_called_class()static::class(非静态类的get_class($this))为了获取放置代码的类的类名,我知道这三种可能性:get_class()__CLASS__self::class是否有任何我现在可以忽略的差异?一种方式相对于另一种方式的潜在优势和劣势是什么? 最佳答案 之间的差异get_class()ret

PHP 7 fatal error :static::class 不能用于编译时类名解析

当前的Travis-CIPHP7构建在执行以下代码时抛出以下错误:PHP7Fatalerror:static::classcannotbeusedforcompile-timeclassnameresolutiontraitEloquentValidatingTrait{//Somedeclarationsskipped/***Eloquentwillcallthisonmodelboot*/publicstaticfunctionbootEloquentValidatingTrait(){//CallingModel::saving()andaskingittoexecuteasse

php - "Static methods are death to testability"- 替代构造函数的替代品?

据说"staticmethodsaredeathtotestability"。如果是这样,下面的可行替代模式是什么?classUser{private$phone,$status='default',$created,$modified;publicfunction__construct($phone){$this->phone=$phone;$this->created=newDateTime;$this->modified=newDateTime;}publicstaticfunctiongetByPhone(PDO$pdo,$phone){$stmt=$pdo->prepare(

php - PHP 5.2 中的类继承 : Overriding static variable in extension class?

我需要能够在从基类扩展基类的类中使用静态变量集。考虑一下:classAnimal{publicstatic$color='black';publicstaticfunctionget_color(){returnself::$color;}}classDogextendsAnimal{publicstatic$color='brown';}echoAnimal::get_color();//prints'black'echoDog::get_color();//alsoprints'black'这在PHP5.3.x中非常有效(Dog::get_color()打印'brown'),因为它

android - Nexus Player (Android TV) YouTubeAndroidPlayerApi 错误 : "An error occurred when initializing the YouTube player."

我正在使用YouTubeandroid播放器API来播放一些youtube视频。我的代码在以下方面运行良好:三星S3三星GalaxyTabIIINexus7(Android5.1.1)但它不适用于NexusPlayer。我收到错误:“初始化YouTube播放器时出错。”我在Nexus播放器上的Youtube应用是1.0.5.5版本我看不到YouTube应用程序已过时的任何迹象,也看不到任何更新方式。如果这是问题所在,我将说明如何更新它。我认为我的list没问题:提前致谢 最佳答案 这是因为适用于Android的YouTubeSDK(

android - ActivityInstrumentationTestCase2和static final : fields become null after first test的使用

这看起来真的像是发生了一些魔法,我很想知道为什么会这样:)这是我的单元测试:publicclassSelectThemeActivityTestextendsActivityInstrumentationTestCase2{privatefinalstaticint[]STATIC_ARRAY={0,1,2};publicSelectThemeActivityTest(){super("com.the7art.simplewallpaper",SelectThemeActivity.class);}@OverrideprotectedvoidsetUp()throwsException