Home  >  Article  >  Backend Development  >  new static()是做什么用的?该如何处理

new static()是做什么用的?该如何处理

WBOY
WBOYOriginal
2016-06-13 13:33:391445browse

new static()是做什么用的?

PHP code
<!--

Code highlighting produced by Actipro CodeHighlighter (freeware)
http://www.CodeHighlighter.com/

-->
namespace myNamespace{
 
    class MyClass {
        public function Show(){
                

            $a = new static('a',1,'b',32,$_GET);
            var_dump($a);
        }
    } 
}


输出了
object(myNamespace\MyClass)#2 (0) { }

没看明白这个是干嘛的?

------解决方案--------------------
new static new self 都是实例化当前类, 但是new static只有代码所在的类,就是子类如果没有重写的话那么实例化的就是父类。 而new self就是严格的当前类

------解决方案--------------------
燃烧吧火鸟说的对!
------解决方案--------------------
顶起
探讨

new static new self 都是实例化当前类, 但是new static只有代码所在的类,就是子类如果没有重写的话那么实例化的就是父类。 而new self就是严格的当前类

------解决方案--------------------
探讨

这个是我模仿写的一个简单的。在看SYMFONY的代码引用:

你这都是从哪找来的代码?
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn