LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Probleme with my programme (https://www.linuxquestions.org/questions/programming-9/probleme-with-my-programme-456739/)

youreal 06-20-2006 07:16 PM

Probleme with my programme
 
After i installed the php5,when i running my programme
will have a error as follow:
Fatal error: Using $this when not in object context in /home/cityleft/regmail/1mysql.php on line 13

any body know this? how can i fix it? thanx

demon_vox 06-20-2006 07:45 PM

Hi,
its very simple, you are using $this when you are not in an object context. $this represents an instance of your object, so, for example, it doesnt have a meaning if you use it in a static method.
If you can post just the code where it fails maybe we can guess some more.

Greetings.

youreal 06-20-2006 08:27 PM

Quote:

Originally Posted by demon_vox
Hi,
its very simple, you are using $this when you are not in an object context. $this represents an instance of your object, so, for example, it doesnt have a meaning if you use it in a static method.
If you can post just the code where it fails maybe we can guess some more.

Greetings.

$this->hd=mysql_connect($host,$user,$psw)or die("please try again later !");
mysql_select_db($name, $this->hd ) or die ("please try again later !");

As above $this will appear error,i am sure that the programme is no problem,because it running ok for many months! Since upgrade php to php5,the programme will make a mistake ,it's made me so confuse,I searched all the web about the problem,somebody said it's
a bug in the pear,isn't it??

demon_vox 06-20-2006 08:40 PM

Hi,
and where is this code in? if it just in the "main" part or in a function it will be wrong. If you use $this you must put it in the code of a method.
Be careful because many thing that PHP4 allowed are no longer allowed in PHP5, but are rightfully disallowed :) (there are good reason for it).

If you are just using $this->hd and you dont have another thing using $this, you could just replace it by $hd and it should work. But whats important to know if you are using an object or not.

Greetings!

youreal 06-20-2006 09:09 PM

Thanks a lot first~
yes,you are right.This code is in a function,maybe you are right! ok,let me check it more times
thanx again

youreal 06-20-2006 09:33 PM

I did it as your said, replace it by $hd and now it work well as before.
3X!!!


All times are GMT -5. The time now is 02:47 PM.