From: Vahis on 11 Jun 2010 12:27 I know, OT, sorry for that, but I also know there is knowledge in this group :) Here's a small snipplet <code> if ($days > 0) { $uptimeString .= $days; $uptimeString .= (($days == 1) ? " day" : " days"); </code> which gives a 'PHP Notice: Undefined variable' in Apache error log. This has appeared (and some other stuff) after some php upgrade. I have been able to fix the rest but this one is still there. What needs to be changed in the above code? As you can see I'm totally clueless in coding And I know it's just a notice but I'd still rather fix the code than change the error level in logging ;) Vahis -- http://waxborg.servepics.com openSUSE 11.2 (x86_64) 2.6.31.12-0.2-default 19:09pm up 38 days 23:21, 12 users, load average: 0.69, 0.38, 0.20
From: Malcolm on 11 Jun 2010 12:46 On Fri, 11 Jun 2010 16:27:02 GMT Vahis <waxborg(a)gmail.com.invalid> wrote: > I know, OT, sorry for that, > but I also know there is knowledge in this group :) > > Here's a small snipplet > > <code> > if ($days > 0) { > $uptimeString .= $days; > $uptimeString .= (($days == 1) ? " day" : " days"); > </code> > which gives a 'PHP Notice: Undefined variable' in Apache error log. > > This has appeared (and some other stuff) after some php upgrade. > I have been able to fix the rest but this one is still there. > > What needs to be changed in the above code? > As you can see I'm totally clueless in coding > > And I know it's just a notice but I'd still rather fix the code than > change the error level in logging ;) > > Vahis Hi There should be a a closing } else is $days defined? eg $days = intval($seconds / 86400); -- Cheers Malcolm ��� (Linux Counter #276890) SUSE Linux Enterprise Desktop 11 (x86_64) Kernel 2.6.32.12-0.7-default up 1 day 2:43, 2 users, load average: 0.08, 0.07, 0.11 GPU GeForce 8600 GTS Silent - CUDA Driver Version: 195.36.15
From: David Bolt on 11 Jun 2010 22:55 On Friday 11 Jun 2010 17:27, while playing with a tin of spray paint, Vahis painted this mural: > I know, OT, sorry for that, > but I also know there is knowledge in this group :) > > Here's a small snipplet > > <code> > if ($days > 0) { > $uptimeString .= $days; > $uptimeString .= (($days == 1) ? " day" : " days"); > </code> > which gives a 'PHP Notice: Undefined variable' in Apache error log. Have you checked to see where $days and $uptimeString are defined? > This has appeared (and some other stuff) after some php upgrade. > I have been able to fix the rest but this one is still there. > > What needs to be changed in the above code? > As you can see I'm totally clueless in coding So was I, although I've improved a little bit[0] since the last time I posted here about PHP and databases[1]. > And I know it's just a notice but I'd still rather fix the code than > change the error level in logging ;) Try calling the script using the command line. Apart from anything else, you'll get to see which line and variable name is causing the error, something like this: davjam(a)moray:~/sync> php test.php PHP Notice: Undefined variable: Test in /home/davjam/sync/test.php on line 3 davjam(a)moray:~/sync> cat test.php <?php $test=1; printf("%s\n",$Test); // deliberate error, but this line number and variable should be identified ?> davjam(a)moray:~/sync> And, if needs be, you can write a small wrapper to add a $_POST and/or $_GET array populated with the required names and values before calling your script. This helps in cases where your script is called as the results of a form submission and lets you test control values that you know what the results should be. Another useful thing is to use the cli version to do a syntax check: davjam(a)moray:~/sync> php -l test.php No syntax errors detected in test.php I've found it comes in very useful when writing big scripts and I manage to miss off a ';' somewhere. [0] I'm even writing shell scripts in php rather than bash. One of them is a wrapper around the build script used for package building. It's only 747 lines, and lets me build for any version of (open)SUSE that I have mirrored. It's a sort of poor mans build service[2], except it requires starting manually. [1] I still see spiders looking at director.php and the various sorting options that were posted :) [2] And would be rarely used except for the fact that I now can't get a local build service to actually run. Was okay until I did an upgrade and then things went all to hell in a hand basket. Even a complete removal of the packages and databases to do a fresh start didn't work. Regards, David Bolt -- Team Acorn: www.distributed.net openSUSE 11.0 32b | | | openSUSE 11.3M7 32b | openSUSE 11.1 64b | openSUSE 11.2 64b | TOS 4.02 | openSUSE 11.1 PPC | RISC OS 4.02 | RISC OS 3.11
From: Vahis on 12 Jun 2010 02:41 On 2010-06-12, David Bolt <blacklist-me(a)davjam.org> wrote: > On Friday 11 Jun 2010 17:27, while playing with a tin of spray paint, > Vahis painted this mural: > >> which gives a 'PHP Notice: Undefined variable' in Apache error log. > > Have you checked to see where $days and $uptimeString are defined? Tried, yes. Php just isn't in my set of skills :( It's a script that I found long ago, it used to have no errors AFAIR but after some php version change there's been this notice. > <snip> > > So was I, although I've improved a little bit[0] since the last time I > posted here about PHP and databases[1]. I remember that. That's roughly when I noticed that programming is not necessarily my cup of tea. Purchasing a two inch thick book about Php5/MySQL didn't get me anywhere. It looks great in the book shelf though. > > Try calling the script using the command line. That gives the same as Apache log. It says PHP Notice: Undefined variable: uptimeString in uptime.php on line 21 When I look at line 21 in Kate I don't know what the fault there is. Instead of pasting the whole code here it can be seen at http://waxborg.servepics.com/testsite/uptime.php > > Another useful thing is to use the cli version to do a syntax check: > > davjam(a)moray:~/sync> php -l test.php > No syntax errors detected in test.php I get the same. > I've found it comes in very useful when writing big scripts and I > manage to miss off a ';' somewhere. Great tip for the future :) > > [1] I still see spiders looking at director.php and the various sorting > options that were posted :) I went to OpenDB at that time, rolling my own turned out to be impossible. http://waxborg.servepics.com/OpenDb There were some notices in there, too, after php version change. I found them and was able to fix them then though. Vahis -- http://waxborg.servepics.com openSUSE 11.2 (x86_64) 2.6.31.12-0.2-default 09:06am up 39 days 13:18, 13 users, load average: 0.11, 0.05, 0.06
From: graham on 12 Jun 2010 03:43
On Sat, 12 Jun 2010 06:41:21 +0000, Vahis wrote: > When I look at line 21 in Kate I don't know what the fault there is. > Instead of pasting the whole code here it can be seen at > http://waxborg.servepics.com/testsite/uptime.php >> That page renders ok in firefox and konquerer with os11.1 kde3.5. |