473,465 Members | 2,124 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Echoing the integer 0 (zero)

Probably it's something dumb that I'm doing/not doing, but echo
doesn't seem to want to echo a literal zero when the value of some var
is zero. E.g.:

$foo = 0 ;
echo 'foo is ' . $foo ;

yields:

foo is

not

foo is 0

So far I've been kludging it with $foo?$foo:'0', but I find it strange
to have to do that, not to mention annoying :-) Is it something I'm
doing, or is that a real deficiency in the language?

Thanks,
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
Jul 17 '05 #1
6 6294
Margaret MacDonald, being the foo Margaret MacDonald is, wrote:
Probably it's something dumb that I'm doing/not doing, but echo
doesn't seem to want to echo a literal zero when the value of some var
is zero. E.g.:

$foo = 0 ;
echo 'foo is ' . $foo ;

yields:

foo is

not

foo is 0

So far I've been kludging it with $foo?$foo:'0', but I find it strange
to have to do that, not to mention annoying :-) Is it something I'm
doing, or is that a real deficiency in the language?

Thanks,
Margaret


0 is the same thing as NULL. If you did:

$foo = '0'; //this makes foo a string
echo 'foo is ' . $foo;

It would display a zero;

--
Sharif T. Karim
....you don't know wrath yet...
Jul 17 '05 #2
Sharif T. Karim wrote:
Margaret MacDonald, being the foo Margaret MacDonald is, wrote:
Probably it's something dumb that I'm doing/not doing, but echo
doesn't seem to want to echo a literal zero when the value of some var
is zero. E.g.:

$foo = 0 ;
echo 'foo is ' . $foo ;

yields:

foo is

not

foo is 0

So far I've been kludging it with $foo?$foo:'0', but I find it strange
to have to do that, not to mention annoying :-) Is it something I'm
doing, or is that a real deficiency in the language?

Thanks,
Margaret
0 is the same thing as NULL. If you did:


Are you sure? According to the documentation, NULL and zero are
different values. Unless I misread something, a variable only has a
NULL value either before it's initialised or if it's explicitly set to
NULL. Setting it to integer 0 should have the same effect (apart from
the actual value) as setting it to integer 1.

$foo = '0'; //this makes foo a string
echo 'foo is ' . $foo;

It would display a zero;


--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
Jul 17 '05 #3
On Fri, 09 Jul 2004 16:29:47 GMT, Margaret MacDonald
<sc**********@att.not.invalid> wrote:
Probably it's something dumb that I'm doing/not doing, but echo
doesn't seem to want to echo a literal zero when the value of some var
is zero. E.g.:

$foo = 0 ;
echo 'foo is ' . $foo ;

yields:

foo is

not

foo is 0

So far I've been kludging it with $foo?$foo:'0', but I find it strange
to have to do that, not to mention annoying :-) Is it something I'm
doing, or is that a real deficiency in the language?


What version do you get this behaviour in? It appears wrong and is
inconsistent with the results I get, which are as expected:

andyh@server:~/public_html$ php -v
PHP 4.3.7RC1 (cli) (built: May 29 2004 20:17:57)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

andyh@server:~/public_html$ cat test.php
<?php
$foo = 0 ;
echo 'foo is ' . $foo ;
echo "\n";
?>

andyh@server:~/public_html$ php -q test.php
foo is 0

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #4
On Fri, 09 Jul 2004 18:40:39 GMT, "Sharif T. Karim" <sh****@nyc.rr.com> wrote:
0 is the same thing as NULL.


No, it isn't.

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space
Jul 17 '05 #5

"Andy Hassall" <an**@andyh.co.uk> wrote in message
news:rc********************************@4ax.com...
On Fri, 09 Jul 2004 16:29:47 GMT, Margaret MacDonald
<sc**********@att.not.invalid> wrote:
Probably it's something dumb that I'm doing/not doing, but echo
doesn't seem to want to echo a literal zero when the value of some var
is zero. E.g.:

$foo = 0 ;
echo 'foo is ' . $foo ;

yields:

foo is

not

foo is 0

So far I've been kludging it with $foo?$foo:'0', but I find it strange
to have to do that, not to mention annoying :-) Is it something I'm
doing, or is that a real deficiency in the language?


What version do you get this behaviour in? It appears wrong and is
inconsistent with the results I get, which are as expected:

andyh@server:~/public_html$ php -v
PHP 4.3.7RC1 (cli) (built: May 29 2004 20:17:57)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

andyh@server:~/public_html$ cat test.php
<?php
$foo = 0 ;
echo 'foo is ' . $foo ;
echo "\n";
?>

andyh@server:~/public_html$ php -q test.php
foo is 0

--
Andy Hassall <an**@andyh.co.uk> / Space: disk usage analysis tool
http://www.andyh.co.uk / http://www.andyhsoftware.co.uk/space


It is wrong and unexpected, for sure.

OP, perhaps you should try

echo "foo is ".(int)$foo;

See if that helps out.
-- Matt
Jul 17 '05 #6
Andy Hassall wrote:
On Fri, 09 Jul 2004 16:29:47 GMT, Margaret MacDonald
<sc**********@att.not.invalid> wrote:
Probably it's something dumb that I'm doing/not doing, but echo
doesn't seem to want to echo a literal zero when the value of some var
is zero. E.g.:

$foo = 0 ;
echo 'foo is ' . $foo ;

yields:

foo is

not

foo is 0

So far I've been kludging it with $foo?$foo:'0', but I find it strange
to have to do that, not to mention annoying :-) Is it something I'm
doing, or is that a real deficiency in the language?


What version do you get this behaviour in? It appears wrong and is
inconsistent with the results I get, which are as expected:

andyh@server:~/public_html$ php -v
PHP 4.3.7RC1 (cli) (built: May 29 2004 20:17:57)
Copyright (c) 1997-2004 The PHP Group
Zend Engine v1.3.0, Copyright (c) 1998-2004 Zend Technologies

andyh@server:~/public_html$ cat test.php
<?php
$foo = 0 ;
echo 'foo is ' . $foo ;
echo "\n";
?>

andyh@server:~/public_html$ php -q test.php
foo is 0


I'm running 4.3.7, but it appeared in 4.3.0 before that. But I must
be bending something out of shape, because the problem appears in the
production code, but not (now) in test code.

How annoying. I'll have to see if I can figure out what I'm doing
that's confusing it.

Thanks for the response, Andy.
Margaret
--
(To mail me, please change .not.invalid to .net, first.
Apologies for the inconvenience.)
Jul 17 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: stevek | last post by:
How do I format an integer. Add commas. 1234565 1,234,565 TIA
15
by: I wish | last post by:
#include <string.h> int a; memset( a, 0, sizeof(a) ); Does that guarantee all bits zero? -- |
17
by: Mantorok Redgormor | last post by:
are all integers represented internally as just bit vectors? -- nethlek
4
by: Ray | last post by:
When a single-bit bitfield that was formed from an enum is promoted/cast into an integer, does ANSI C say anything about whether that integer should be signed or unsigned? SGI IRIX cc thinks it is...
3
by: Janice | last post by:
I got this question from my textbook and I cannot understand the theory. When a signed positive integer X divided by pow(2,k), the result is shifting k bits to right and putting w-k bits of 0 from...
33
by: gk245 | last post by:
I mean, anything that follows a 0 is automatically turned into a octal number. I want to have a integer variable that will hold numbers as integers even if they begin with a zero. for example:...
232
by: robert maas, see http://tinyurl.com/uh3t | last post by:
I'm working on examples of programming in several languages, all (except PHP) running under CGI so that I can show both the source files and the actually running of the examples online. The first...
46
by: lovecreatesbea... | last post by:
Do you prefer malloc or calloc? p = malloc(size); Which of the following two is right to get same storage same as the above call? p = calloc(1, size); p = calloc(size, 1);
17
by: matevzb | last post by:
I've ran into some fishy code that, at first glance, is buggy, but it seems to work correctly and none of the compilers I've tried (five so far, on various systems) gives any warnings. The code:...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.