简体   繁体   English

严格标准:非静态方法

[英]Strict Standards: Non-static method

I got a problem over here, I'm trying to get my scripting better, but I'm getting this error: 我在这里遇到了一个问题,我试图使自己的脚本更好,但出现此错误:

Strict Standards: Non-static method DB::query() should not be called statically in C:\xampp\htdocs\Checkin\content\news_index.php on line 2

some guy already told me I'm using static and non-static the wrong way, but i really don't get this error. 有人已经告诉我我以错误的方式使用静态和非静态,但是我确实没有收到此错误。

The error is at a few lines, 2, 3 and 9. 错误出现在第2、3和9行。

This is my news_index.php: 这是我的news_index.php:

<?php
$pickQuery = DB::Query("SELECT * FROM `cms_picks` WHERE `enabled` = 'true' ORDER BY `id` DESC LIMIT 6");
if(DB::num_rows($pickQuery) > 0){
?>

                <div class="heading blue">Wat gebeurt er in <?php echo $hotelnaam; ?>? </div>
                <div class="inner news_picks">
                    <?php
                    while($pickFetch = DB::fetch_array($pickQuery)){
                    ?>
                    <div class="pick">
                        <a class="url" href="<?php echo $pickFetch['url']; ?>" ><div class="image" style="background: url('<?php echo htmlentities($pickFetch['image']); ?>') no-repeat; height: 60px; width: 160px; float: left; border-radius: 7px; border: 2px solid #ADADAD;  "></div></a>
                        <div class="text" >
                            <a class="url" style="font-size: 15px;" href="<?php echo $pickFetch['url']; ?>"><b><?php echo htmlentities($pickFetch['title']); ?></b></a><br />
                            <?php echo htmlentities($pickFetch['desc']); ?>
                        </div>
                        <div style="clear: both;"></div>
                    </div>
                    <?php
                    }
                    ?>

                </div>

<?php } ?>

I hope that someone can help... 我希望有人可以帮助...

Wesley 卫斯理

I'm not sure which library you are using, but the error seems pretty clear: you should not be calling DB::Query through its class name but rather create an object first: 我不确定您使用的是哪个库,但是错误似乎很清楚:您不应该通过类名来调用DB::Query ,而是先创建一个对象:

$db = new DB( /* whatever parameters the constructor takes, see documentation */ );
// ...
$pickQuery = $db->query("SELECT ... ");

If you look at your DB class then you'll see the function Query defined as a member function or instance method. 如果查看您的DB类,那么您会看到定义为成员函数或实例方法的函数Query Member functions are called on an instance of the class. 成员函数在类的实例上调用。 In your case it would be something similar to: 在您的情况下,它将类似于:

$db = new DB();
$db->Query($sql);

However, you're calling Query statically, ie DB::Query($sql) . 但是,您是在静态调用Query ,即DB::Query($sql) The difference is, instance variables and methods are called on object using arrow -> operator and static functions and variables are accessed using scope resolution :: operator on the Class. 不同之处在于,使用箭头->运算符在对象上调用了实例变量和方法,而使用Class上的作用域解析::来访问静态函数和变量。

Note: $sql used here is a placeholder for your query. 注意:此处使用的$sql是查询的占位符。

Had your Query function been defined static as static function Query($sql) in DB class then your code would not have complained. 如果您在DB类中将Query函数定义为static function Query($sql) ,那么您的代码就不会抱怨。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 严格标准:非静态方法 - Strict Standards: Non-static method 严格标准:非静态方法(joomla和roksprocket) - Strict Standards: Non-static method (joomla and roksprocket) 严格标准:非静态方法DOMDocument :: load()rss feed - Strict Standards: Non-static method DOMDocument::load() rss feed 严格标准:非静态方法,假设$ this来自不兼容的上下文 - Strict Standards: Non-static method, assuming $this from incompatible context PHP严格标准:非静态方法Fatal :: dbError() - PHP Strict Standards: Non-static method Fatal::dbError() 严格标准:只能通过引用传递变量&严格标准:非静态方法 - Strict Standards: Only variables should be passed by reference & Strict Standards: Non-static method 严格的标准非静态方法 - Strict standards non static method 严格标准:不应静态调用非静态方法modJumiHelper :: getCodeWritten() - Strict Standards: Non-static method modJumiHelper::getCodeWritten() should not be called statically 严格标准:非静态方法StreamComment :: getCommentsHTML()不应静态调用,假设$ this来自不兼容的上下文 - Strict Standards: Non-static method StreamComment::getCommentsHTML() should not be called statically, assuming $this from incompatible context 严格标准:不应在以下位置静态调用非静态方法lang :: utf8decode() - Strict Standards: Non-static method lang::utf8decode() should not be called statically in
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM