dongyun234854 2013-12-01 11:03 采纳率: 0%
浏览 19
已采纳

严格标准:非静态方法

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
ews_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.

This is my 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

  • 写回答

2条回答 默认 最新

  • dongyan9838 2013-12-01 11:07
    关注

    If you look at your DB class then you'll see the function Query defined as a member function or instance method. 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, i.e. 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.

    Note: $sql used here is a placeholder for your query.

    Had your Query function been defined static as static function Query($sql) in DB class then your code would not have complained.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!