ground between self and static?

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() {

PHP 5.2 Equivalent to Late Static Binding (new 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.2相当于后期静态绑定(新的静态)?

我试图制作一个脚本,它是为php 5.3在php 5.2服务器上工作而构建的。 该脚本使用了很多迟到的静态绑定,如: return new static($options); 什么是在PHP 5.2中相当于这个? 它会以某种方式成为新的自我? 或者是不可能达到同样的效果...... 谢谢 编辑: 这是一个相关的问题新的自我与新的静态 Juts试图把我的头包裹在这个晚期的静态绑定内容中...... 我认为唯一的方法是传递一个构建你的单例的受保护静态方法和一

Calling a PHP Static Property through an Object Scope $Object::$ClassProperty

[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静态属性$ Object :: $ ClassProperty

[我正在使用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

Why in late static binding child class gets data from parent and current methods

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;

Method Overriding vs Late Static Binding?

当它带有继承时,方法重写和后期静态绑定究竟有什么区别? 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中迟到的静态绑定究竟是什么?

PHP late static binding scope confusion

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后期静态绑定范围混淆

从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" 它按照所述的方式工作 但是,以下示例会引发

self:: referring to derived class in static methods of a parent class

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

self ::引用父类的静态方法中的派生类

我喜欢这个答案中提出的想法,允许在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

How to invoke a method statically?

<?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

Returning of new $this with abstract classes

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

PHP Late Static Binding in Singleton

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

单身人士PHP后期静态绑定

我从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::$_