草庐IT

language-construct

全部标签

php - 扩展 PDO 的类 - parent::__construct 不起作用,但创建新的 PDO 可以

我正在尝试编写一个PDO包装器,但我在构造函数方面遇到了一些问题。理想情况下,我想调用父级的构造函数,但由于某种原因,这是行不通的。我尝试(测试)检查是否创建了一个新的PDO并且确实有效,我发现这最令人困惑。这是我的代码:classdbextendsPDO{private$dbconn;publicfunction__construct(){$dsn='mysql:dbname='.MYSQL_DB.';host='.MYSQL_HOST;$user=MYSQL_USER;$pw=MYSQL_PW;try{$this->dbconn=parent::__construct($dsn,$

php - <?php ?> 和 &lt;script language ="php">&lt;/script&gt; 的区别

我只是浏览了那里的PHP教程,我发现我们可以使用编写我们的PHP代码。也有标签,我试图弄清楚这和之间的区别标签和优点或缺点,但没有找到任何东西,谁能告诉我区别。提前致谢。 最佳答案 我认为,就语义而言没有优点或缺点。根据PHPmanual:TherearefourdifferentpairsofopeningandclosingtagswhichcanbeusedinPHP.Twoofthose,and,arealwaysavailable.另外,请注意:IfyouareembeddingPHPwithinXMLorXHTMLyou

PHP Mongo:注意:Mongo::__construct(): 解析服务器

我想知道为什么我会收到以下php通知:(!)Notice:Mongo::__construct():parsingserversinC:\htdocs\multishop\library\Lupi\Resource\Odm.phponline38CallStack#TimeMemoryFunctionLocation10.0004138504{main}()..\index.php:020.0130667392Zend_Application->bootstrap()..\index.php:2530.0130667488Zend_Application_Bootstrap_Boots

php - self::__construct() 和 new self() 之间的确切区别

你能告诉我returnself::__construct()和returnnewself()之间的确切区别吗?看起来实际上可以在创建对象时从__construct()调用返回一个self::__construct(),返回对象本身就像第一个__construct()从未被调用过。 最佳答案 这在代码中得到了最好的说明:classMyClass{public$arg;publicfunction__construct($arg=NULL){if($arg!==NULL)$this->arg=$arg;return$this->arg;

php - 在其他方法中使用来自 __construct() 的变量

我在__construct()中定义了一个新变量,我想在这个class的另一个function中使用它。但是我的变量在另一个函数中是空的!这是我的代码:classtestObject{function__construct(){global$c;$data=array("name"=>$c['name'],"family"=>$c['family']);}functionshowInfo(){global$data;print_r($data);}} 最佳答案 在构造函数中将变量$data声明为全局变量:function__cons

PHP/CodeIgniter - 在 __construct() 中设置变量,但它们不能从其他函数访问

我很高兴遇到一个变量范围问题。也许我只是需要更多的咖啡...这是我的(简化的)代码-这是在CodeIgniter2中:classAgentextendsCI_Controller{publicfunction__construct(){parent::__construct();$this->load->model('agent_model');//Getpreliminarydatathatwillbeoften-usedinAgentfunctions$user=$this->my_auth_library->get_user();$agent=$this->agent_model

php - CakePHP 中的本地化路由 : How to redirect to default language

自2012年以来,thispost似乎是关于如何在CakePHP中执行本地化路由的最权威资源(下面复制的代码)。它运行良好,但有一个异常(exception):它不会重定向缺少语言前缀的请求。例如,http://example.com将显示与http://example.com/eng相同的内容(如果英语是默认语言)。同样,如果不是主页:http://example.com/foo/bar/=>http://example.com/eng/foo/bar.评论中提到了这个问题,但没有确定的解决方案,这就是我正在寻找的。代码。//Step1:app/Config/routes.phpRo

php - 我必须在构造函数的第一行调用 parent::__construct() 吗?

我知道在Java中,构造函数中的super()必须作为重写构造函数的第一行调用。这是否也适用于PHP中的parent::__construct()调用?我发现自己写了一个这样的异常类:classMyExceptionextendsException{publicfunction__construct($some_data){$message='';$message.=format_data($some_data);$message.='waspassedbutwasnotexpected';parent::__construct($message);}}我想知道这是否会被视为PHP中的

PHPStorm 对 __construct() 的@return void 发出尖叫

我正在使用PHPStorm并试图找出当__construct()在其PHPDocs中有@returnvoid时如何让它停止尖叫...根据PHPDocs,void是有效的,或者可以省略@return。话虽这么说,有没有办法解决这个问题或者这是一个错误? 最佳答案 不幸的是,您不能只关闭这个非常具体的检查。需要关闭整个PHPDoc方法签名检查。幸运的是你可以setthescopeoftheinspection仅作为您自己的项目代码,忽略第3方库和框架。请参阅说明下方右侧的范围下拉列表。您还可以根据具体情况关闭每个PHPDoc注释上方的检

php - laravel 5.4:无法在 __construct 方法中访问 Auth::user()

在以前版本的Laravel中,在我需要访问已登录用户的所有方法中的Controller中,我曾经做过这样的事情:classDashboardControllerextendsController{private$user;function__construct(Request$request){$this->middleware('auth');$this->user=\Auth::user();}functionfunc_1(){$objects=Objects::where('user_id',$this->user->id)->get();}functionfunc_2(){$o