English 中文(简体)
致命错误: 在不反对的情况下使用该笔款项,不适当运作
原标题:Fatal error: Using $this when not in object context no working properly
  • 时间:2011-11-24 12:30:19
  •  标签:
  • php
<?php
class Functions {
    public static function extendSql($dbhost, $dbuser, $dbpass, $dbname) {
        // making the mysql connection dynamically editable
        $mysql_connect  =   mysql_connect($dbhost, $dbuser, $dbpass)or die("Could not connect: " . mysql_error());
        $mysql_select_db =  mysql_select_db($dbname) or die(mysql_error());
    }
    public static function whileLoop($dbuser, $dbpass, $dbname, $sql, $passedData) {
        $this->extendSql($dbuser, $dbpass, $dbname);
        $results = mysql_query($sql);       
        while ($row = mysql_fetch_array($results)) {
        echo $passedData;
        }
    }
}

Functions::whileLoop("root", "", "rand", "SELECT * FROM products",
$hello = "hi all");
?>

我在执行上述法典时有以下错误。

Fatal error: Using $this when not in object context in C:WorkspacehtdocsMisc-2 urbell1coreconfmisc.php on line 13

我做了什么错误? 显然,在我的法典中,这笔钱在分类范围内被提及。

最佳回答

您在固定功能中使用$>,该功能不属于目前的范畴/内容,因此无法使用$this

问题回答

您是在静态功能中打电话this。 只有在您有<条码>功能/代码>的标语时,方可使用<条码>。 您必须使用<代码>自封/代码>关键词来获取固定功能。

将你的代码改为<代码>本身:ExendSql($dbuser,$dbpass,$dbname);

请阅读本手册,以便更多了解<代码>。 关键词

你可以在静态方法中使用这一笔款项,因为这笔钱指的是物体,而不是舱面,而当有人要求静态方法时,你可以保证你有物体。 相反,你可以使用“自己:方法”从同一类别中用固定方法。

You should read up on how PHP OOP works: OO in PHP and also what the difference between classes and objects is: difference between object and class





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签