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

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

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-13 10:19:46
Original
1253 people have browsed it

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);        }    } }
Copy after login

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

没看明白这个是干嘛的?

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

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

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

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

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

你这都是从哪找来的代码?
Related labels:
source:php.cn
Statement of this Website
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
Latest Issues
Hello everyone, new report
From 1970-01-01 08:00:00
0
0
0
What does the new operator do?
From 1970-01-01 08:00:00
0
0
0
Will there be any new ones later?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template