473,383 Members | 1,891 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,383 software developers and data experts.

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 6291
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: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.