0
我想知道更多关于static
的技巧。如果我得到了我的类中有一些静态函数:php静态函数,查询数据库
<?php
class Input {
public function exists($type = 'post') {
switch($type) {
case 'post':
return (!empty($_POST)) ? true : false;
break;
case 'get':
return (!empty($_GET)) ? true : false;
break;
default:
return false;
break;
}
}
public static function get($item) {
if(isset($_POST[$item])) {
return $_POST[$item];
} else if(isset($_GET[$item])) {
return $_GET[$item];
}
return '';
}
}
和spl_autoload_register
我可以使用输入::得到($项目)访问功能;而对于非静态函数,我需要使用它来实例化,$input = new Input();
然后可以通过使用$ input-> exists()来访问函数。
所以,我没有得到区别。我可以从static
方法查询数据库吗? __constructor
是否工作?
我无法找到任何明确的答案在线。
不知道你真的在这里问什么。如果你不知道什么静态手段和它有什么影响,那么阅读手册中的内容:http://www.php.net/manual/en/language.oop5.static.php – CBroe
这是真的基本和太广泛的话题在这里得到解答。你应该阅读一些文档。如果您仍然有问题,那么http://programmers.stackexchange.com/更合适。 – DanMan