WilkoUK Posted 8 hours ago Share Posted 8 hours ago 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. Quote Link to comment https://forums.phpfreaks.com/topic/330360-undefined-really/ Share on other sites More sharing options...
Barand Posted 7 hours ago Share Posted 7 hours ago 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? Quote Link to comment https://forums.phpfreaks.com/topic/330360-undefined-really/#findComment-1659101 Share on other sites More sharing options...
WilkoUK Posted 5 hours ago Author Share Posted 5 hours ago Fair comments but no, it’s an unconditional declaration and in the same scope. #baffled Quote Link to comment https://forums.phpfreaks.com/topic/330360-undefined-really/#findComment-1659107 Share on other sites More sharing options...
mac_gyver Posted 4 hours ago Share Posted 4 hours ago (edited) 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 4 hours ago by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/330360-undefined-really/#findComment-1659118 Share on other sites More sharing options...
Solution WilkoUK Posted 4 hours ago Author Solution Share Posted 4 hours ago Ok.. I am a total plonker! I looked a bit harder and the declarations are in fact made conditionally. I've moved them outside of the if() block. That'll solve the issue. My fault, my bad, apologies for wasting peoples time. Quote Link to comment https://forums.phpfreaks.com/topic/330360-undefined-really/#findComment-1659120 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.