Non-static error

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Non-static error

Post by gazzieh »

Hi

I have seen this around but cannot find a direct solution to this issue.

I have the following code line:

Code: Select all

$settings = DataSettings::getSettings();
This is based upon a class DataSettings and is obviously getting the database connection values from the function getSettings.

I understand that PHP5 (my new test server installation) is the reason for this error and that I could potentially declare the function as static but I get the sense that this is a poor solution.

I have seen recommendations to replace :: with = but this clearly makes no sense with my code line above.

So, how best to make my old code PHP5 compatible?
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Non-static error

Post by Weirdan »

If the method is static declare it as such.
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: Non-static error

Post by gazzieh »

Yeah, okay. Dumb question with obvious answer.

I now encounter a new issue.

I have a series of $_GET statements that have been running fine under PHP4 but again under PHP5 I am getting an error.

The fact is that the $_GET statements all react to a $_GET statement but works on the principle that if they are not present then the code will simply be missed.

So, I have, for example...

Code: Select all

if ($_GET['action']=='error')
Yet, if 'action' does not exist then the usual reaction is for the code to be ignored. However, I am now getting the following error:

Notice: Undefined index: action in [LOCATION]\index.php on line 15

So, aside from always adding in a catchall statement (combining the above code with a check for existence), which would be messy I am unsure if there is a work around or if the error I have is not an actual PHP5 error but something related to the previous error (though I cannot see any connection).
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Non-static error

Post by Weirdan »

gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: Non-static error

Post by gazzieh »

Sorry Weirdan but this makes no sense to me.

I have a switch command that seems currently to fail due to the non-existence of the variable defined by the $_GET statement. I have no issues with this working on the production copy (under PHP4), which responds as I would expect it to; if the $_GET value is not defined then do the DEFAULT setting.

So, I simply need to know if this has changed within PHP5 and if so, what the work around is. I am assuming I am not the only person who has encountered this and could do with direction and advice. Sorry, but your link offers me no assistance. :o(
User avatar
Weirdan
Moderator
Posts: 5978
Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine

Re: Non-static error

Post by Weirdan »

gazzieh wrote:So, I simply need to know if this has changed within PHP5
No, it was considered error (E_NOTICE) even in PHP4. What could be different though is php settings on your two hosts.
gazzieh
Forum Commoner
Posts: 40
Joined: Wed May 19, 2010 7:46 am

Re: Non-static error

Post by gazzieh »

Yeah, I am beginning to realise that what I perceived as basic logic was in fact sloppy programming.

I am being told that the best solution is to test for the variable with isset(), which means messy code for if statements and preceeding code for switches until I can rebuild the code. Oh, how much fun!

Anyhow, I have to recode for HTML 5 at some stage so may as well add this to the developmental plan.

Thanks for the help.
Post Reply