Jump to content

Undefined.... really?


Go to solution Solved by WilkoUK,

Recommended Posts

Hi folks, first time here although I've been coding in PHP for more years than I can remember.

I'm in the process of moving some legacy code from v7.4 upto 8.2, which has the following declaration:
$pri_sec_replaced = FALSE;

However, when executed I receive the following warning:
PHP Warning:  Undefined variable $pri_sec_replaced in ...

Am I missing something fundamental here? As far as I'm concerned the boolean has been declared and set.

Thanks in advance.

Link to comment
https://forums.phpfreaks.com/topic/330360-undefined-really/
Share on other sites

A couple of possibilities spring to mind.

Are the definition and the usage of the variable inside the same scope; for example - is it used inside a function but defined outside that function?

Is the definition inside a conditional block of code (eg if() )so that it has not been executed because the condition was false?

Link to comment
https://forums.phpfreaks.com/topic/330360-undefined-really/#findComment-1659101
Share on other sites

this isn't a php version problem. the problem may have always existed, but you just likely have error_reporting/display_errors set to values now that's reporting and displaying this error. note: a nonexistent variable is loosely a false value, so any == or != comparison or if($var) of if(!$var) will logically work.

your code could be unsetting it, or you have a character set problem, where either the definition or usage isn't exactly what it appears to be. i would delete and retype one or both lines or copy just those lines into their own file file and run them.

edit: here's another possibility - the php code where the definition is at, isn't actually php code, due to the use of a short open tag.

if you cannot determine the cause of the problem, you will need to post enough of the code that reproduces the problem.

 

Edited by mac_gyver
Link to comment
https://forums.phpfreaks.com/topic/330360-undefined-really/#findComment-1659118
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.