Denial is not a programming paradigm...simonmlewis wrote:What if there is a block?
Its still being set at zero anyway.
It does work as we see results from it.
Undefined variable - why am I getting these?
Moderator: General Moderators
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Undefined variable - why am I getting these?
(#10850)
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Undefined variable - why am I getting these?
You don't even need $count = 0; do you?
Because: $count = $count + 1; sets it - doesn't it?
Because: $count = $count + 1; sets it - doesn't it?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Undefined variable - why am I getting these?
And again: what does $count = unassigned + 1 equal? Obviously in our time/space continuum the addition has to happen before the assignment. Right?
(#10850)
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Undefined variable - why am I getting these?
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.
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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Undefined variable - why am I getting these?
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.simonmlewis wrote:Ok, so $count is set to zero.
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Undefined variable - why am I getting these?
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.
$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.
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Undefined variable - why am I getting these?
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?
(#10850)
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Undefined variable - why am I getting these?
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??
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??
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Undefined variable - why am I getting these?
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?
a very simple test will be replace this line:
for this one
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.
Code: Select all
$count = $count + 1;Code: Select all
$count++;-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Undefined variable - why am I getting these?
Code: Select all
if ($row->bundleroman1 == NULL || $row->bundleroman1 == "")
{ echo "<br/>$row->rcstock";}Code: Select all
if(empty($row->bundleroman1))
{ echo "<br/>$row->rcstock";Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Undefined variable - why am I getting these?
It depends on what you are checking for? What value does $row->bundleroman1 have when it is valid?simonmlewis wrote:This is wrong apparently, so how do I redo this?Code: Select all
if ($row->bundleroman1 == NULL || $row->bundleroman1 == "") { echo "<br/>$row->rcstock";}
That might be one way. See the documentation for the difference between isset() and empty().simonmlewis wrote:Like this?Code: Select all
if(empty($row->bundleroman1)) { echo "<br/>$row->rcstock";
(#10850)
-
simonmlewis
- DevNet Master
- Posts: 4435
- Joined: Wed Oct 08, 2008 3:39 pm
- Location: United Kingdom
- Contact:
Re: Undefined variable - why am I getting these?
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?
ISSET means it has something in it. EMPTY means it's empty.
Does it not?
Love PHP. Love CSS. Love learning new tricks too.
All the best from the United Kingdom.
All the best from the United Kingdom.
Re: Undefined variable - why am I getting these?
Code: Select all
$var = 0;
var_dump(empty($var));
var_dump(isset($var));- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: Undefined variable - why am I getting these?
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.
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.
(#10850)