Home  >  Article  >  Backend Development  >  为什么静态方法不能操作静态变量?该怎么处理

为什么静态方法不能操作静态变量?该怎么处理

WBOY
WBOYOriginal
2016-06-13 13:38:42772browse

为什么静态方法不能操作静态变量?
为什么静态方法不能操作静态变量?解释下哈。。

------解决方案--------------------
静态方法在编译期间就已定义,而操作非静态变量需要一个对象。而这个对象是在运行时才产生的。
大概来说,非静态方法可以操作静态方法和变量。而静态方法不能操作非静态方法和变量。(不过,实际上 php中可以违规的静态调用非静态方法)
http://cn.php.net/manual/zh/language.oop5.static.php
------解决方案--------------------
我说错了没什么关系,只要你不由此变傻就可以了

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