I am looking for a middle ground between SELF and STATIC, without the unexpected behavior of Late Static Binding. Below is my code, with practice results and expected results: <?php class A { public function get_self() { return new self(); } public function get_static() { return new static(); } } class B extends A {} class C { public function static_get_a_self() { return A::
我正在寻找SELF和STATIC之间的中间地带,没有出现Late Static Binding的意外行为。 以下是我的代码,包含练习结果和预期结果: <?php class A { public function get_self() { return new self(); } public function get_static() { return new static(); } } class B extends A {} class C { public function static_get_a_self() { return A::get_self(); } public function static_get_a_static() {
I am trying to make a script that is built for php 5.3 work on a php 5.2 server. The script uses a lot of late static binding like: return new static($options); What is the equivalent to this in php 5.2? would it be new self somehow? Or is it not possible to achieve the same effect... Thanks EDIT: Here is a related question New self vs. new static Juts trying to wrap my head around t
我试图制作一个脚本,它是为php 5.3在php 5.2服务器上工作而构建的。 该脚本使用了很多迟到的静态绑定,如: return new static($options); 什么是在PHP 5.2中相当于这个? 它会以某种方式成为新的自我? 或者是不可能达到同样的效果...... 谢谢 编辑: 这是一个相关的问题新的自我与新的静态 Juts试图把我的头包裹在这个晚期的静态绑定内容中...... 我认为唯一的方法是传递一个构建你的单例的受保护静态方法和一
[I am using WAMP Server with PHP version 5.5.12] Since I have started reading the PHP OOP Books I came to know that static properties or methods should be called like ClassName::$Propertyname; But today I tried this $InitializedClass = new Class($args); echo $InitializedClass::$ClassStaticProperty; //It Worked Please let me understand what did my code do or what wrong I am doing. Any help
[我正在使用PHP版本5.5.12的WAMP Server] 自从我开始阅读PHP OOP书籍后,我开始知道静态属性或方法应该被称为类似 ClassName::$Propertyname; 但今天我试了这个 $InitializedClass = new Class($args); echo $InitializedClass::$ClassStaticProperty; //It Worked 请让我明白我的代码做了什么或者我做了什么错误。 这位学习者衷心感谢任何帮助。 <?php class Human { public $name; static $title; pub
Ok, the title is hard to understand, but I was trying to understand about late static binding, and I saw this answer https://stackoverflow.com/a/35577069/1640606 Which shows the difference as being between those two example: Note, self::$c class A { static $c = 7; public static function getVal() { return self::$c; } } class B extends A { static $c = 8; } B::get
好吧,标题很难理解,但我想了解后期静态绑定,我看到了这个答案https://stackoverflow.com/a/35577069/1640606 其中显示了这两个示例之间的区别: 请注意, self :: $ c class A { static $c = 7; public static function getVal() { return self::$c; } } class B extends A { static $c = 8; } B::getVal(); // 7 后期静态绑定,请注意static :: $ c class A { static $c = 7;
当它带有继承时,方法重写和后期静态绑定究竟有什么区别? Late static binding is essentially method overriding for static methods. There are some subtle differences in how they are actually carried out by the compiler. See What exactly are late static bindings in PHP?
当它带有继承时,方法重写和后期静态绑定究竟有什么区别? 晚期静态绑定本质上是对静态方法的重写。 编译器实际执行的方式有些细微差别。 请参阅PHP中迟到的静态绑定究竟是什么?
From PHP mannual second paragraph, it says that: static:: introduces its scope. I tried the following example accordingly: class Father { public function test(){ echo static::$a; } } class Son extends Father{ protected static $a='static forward scope'; public function test(){ parent::test(); } } $son = new Son(); $son->test(); // print "static forward
从PHP的第二段,它说: static ::引入其范围。 我相应地尝试了下面的例子: class Father { public function test(){ echo static::$a; } } class Son extends Father{ protected static $a='static forward scope'; public function test(){ parent::test(); } } $son = new Son(); $son->test(); // print "static forward scope" 它按照所述的方式工作 但是,以下示例会引发
I liked the idea presented in this answer allowing having something like multiple constructors in PHP. The code I have is similar to: class A { protected function __construct(){ // made protected to disallow calling with $aa = new A() // in fact, does nothing }; static public function create(){ $instance = new self(); //... some important code retur
我喜欢这个答案中提出的想法,允许在PHP中使用多个构造函数。 我有的代码类似于: class A { protected function __construct(){ // made protected to disallow calling with $aa = new A() // in fact, does nothing }; static public function create(){ $instance = new self(); //... some important code return $instance; } static public function createFrom
<?php class Popular { public static function getVideo() { return $this->parsing(); } } class Video extends Popular { public static function parsing() { return 'trololo'; } public static function block() { return parent::getVideo(); } } echo Video::block(); I should definitely call the class this way: Video::block(); and n
<?php class Popular { public static function getVideo() { return $this->parsing(); } } class Video extends Popular { public static function parsing() { return 'trololo'; } public static function block() { return parent::getVideo(); } } echo Video::block(); 我应该这样称呼班级: Video::block(); 而不是初始化它 $video = new
I found some trouble with my code and do not understand why it's doing as it is. Can anyone explain me? Let we have: abstract class AbstractThing { public function search(...) { $ret = false; $data = $database->query(...); foreach($data as $values) { $item = new $this; $item->fill_with_values($values); $r
我在代码中发现了一些问题,不明白为什么它会这样做。 任何人都可以解释我? 让我们有: abstract class AbstractThing { public function search(...) { $ret = false; $data = $database->query(...); foreach($data as $values) { $item = new $this; $item->fill_with_values($values); $ret []= $item; } retur
I has this code from some article on habrahabr.ru: abstract class Singleton { protected static $_instances = array(); protected function __construct() { } public static function getInstance() { $class = get_called_class(); if ( !isset( static::$_instances[$class] ) ) static::$_instances[$class] = new static; return stat
我从habrahabr.ru上的一些文章得到了这段代码: abstract class Singleton { protected static $_instances = array(); protected function __construct() { } public static function getInstance() { $class = get_called_class(); if ( !isset( static::$_instances[$class] ) ) static::$_instances[$class] = new static; return static::$_