Page 3 of 6

Re: Undefined variable - why am I getting these?

Posted: Tue Jul 23, 2013 9:25 pm
by Christopher
simonmlewis wrote:What if there is a block?
Its still being set at zero anyway.
It does work as we see results from it.
Denial is not a programming paradigm... ;)

Re: Undefined variable - why am I getting these?

Posted: Wed Jul 24, 2013 3:17 am
by simonmlewis
You don't even need $count = 0; do you?
Because: $count = $count + 1; sets it - doesn't it?

Re: Undefined variable - why am I getting these?

Posted: Wed Jul 24, 2013 5:55 pm
by Christopher
And again: what does $count = unassigned + 1 equal? Obviously in our time/space continuum the addition has to happen before the assignment. Right?

Re: Undefined variable - why am I getting these?

Posted: Thu Jul 25, 2013 3:47 am
by simonmlewis
Ok, so $count is set to zero.
I then tell it $count (which is zero) is $count (which is zero) + 1.

Nothing else in this page is happening to $count before this, so again, why is it saying it is undefined?
Guess I'll never know.

Re: Undefined variable - why am I getting these?

Posted: Thu Jul 25, 2013 5:07 am
by Celauran
simonmlewis wrote:Ok, so $count is set to zero.
No. No it isn't. I can't tell you exactly why because you refuse to show your code, but it very clearly isn't being set to zero or you would not be getting a notice telling you it's undefined. This really ought to be abundantly clear.

Re: Undefined variable - why am I getting these?

Posted: Thu Jul 25, 2013 5:11 am
by simonmlewis
Ok - $count is not mentioned anywhere else in the code.
$count = 0; is set immediately before the $count + 1 script.

There is no other way I can tell it to be zero. I've even told $count = 0; right at the very top of the page, so there is no question or doubt.

Re: Undefined variable - why am I getting these?

Posted: Thu Jul 25, 2013 10:53 am
by Christopher
Debugging is not about insisting that the PHP parser is wrong. It's about finding where $count is unset. Also, are you positive that the line you are looking at is the line that PHP is complaining about?

Re: Undefined variable - why am I getting these?

Posted: Thu Jul 25, 2013 10:56 am
by simonmlewis
100%
Is there a Firefox way to view what is happening and see if $count is somehow (heaven knows how as it's mentioned ONCE) being ignored/uninitialised? Error Console??

Re: Undefined variable - why am I getting these?

Posted: Thu Jul 25, 2013 11:00 am
by Celauran
PHP is server side, so you can't really do anything to it in your browser. You could try stepping through the code with XDebug.

Re: Undefined variable - why am I getting these?

Posted: Thu Jul 25, 2013 12:21 pm
by mikosiko
a very simple test will be replace this line:

Code: Select all

$count = $count + 1;
for this one

Code: Select all

$count++;
and see if you still getting the message... I'm guessing that you could potentially have a hidden character in the original line that could be the culprit.

Re: Undefined variable - why am I getting these?

Posted: Thu Aug 15, 2013 10:47 am
by simonmlewis

Code: Select all

if ($row->bundleroman1 == NULL || $row->bundleroman1 == "")
{ echo "<br/>$row->rcstock";}
This is wrong apparently, so how do I redo this?

Code: Select all

if(empty($row->bundleroman1))
{ echo "<br/>$row->rcstock";
Like this?

Re: Undefined variable - why am I getting these?

Posted: Thu Aug 15, 2013 3:29 pm
by Christopher
simonmlewis wrote:

Code: Select all

if ($row->bundleroman1 == NULL || $row->bundleroman1 == "")
{ echo "<br/>$row->rcstock";}
This is wrong apparently, so how do I redo this?
It depends on what you are checking for? What value does $row->bundleroman1 have when it is valid?
simonmlewis wrote:

Code: Select all

if(empty($row->bundleroman1))
{ echo "<br/>$row->rcstock";
Like this?
That might be one way. See the documentation for the difference between isset() and empty().

Re: Undefined variable - why am I getting these?

Posted: Thu Aug 15, 2013 5:33 pm
by simonmlewis
If it is not empty, it will have someting like "XLGREEN2". A stock code.
ISSET means it has something in it. EMPTY means it's empty.
Does it not?

Re: Undefined variable - why am I getting these?

Posted: Thu Aug 15, 2013 7:19 pm
by Celauran

Code: Select all

$var = 0;
var_dump(empty($var));
var_dump(isset($var));

Re: Undefined variable - why am I getting these?

Posted: Thu Aug 15, 2013 9:41 pm
by Christopher
Also, take a look at: http://php.net/manual/en/types.comparisons.php

You need to take a look at the bigger picture. The value should be properly initialized so you can do a clean check on it.