You are here: Re: Passing Boolean to a Function « PHP Programming Language « IT news, forums, messages
Re: Passing Boolean to a Function

Posted by David Haynes on 12/17/11 11:52

Greg Scharlemann wrote:
> I'm having an issue passing a boolean to the constructor of an object.
> For some reason, if I pass false into the constructor, it doesn't
> register. If I pass an integer 0, it does. PHP 5 Code below:
>
> ---------------------
> class Test {
> var $testBool;
>
> public function __construct($testBool) {
> print "testBool = $testBool";
> }
> }
>
> $testing = new Test(false); // this just prints "testBool = "
>
> $testing = new Test(0); // this prints "testBool = 0"
>
> --------------------
> Seems to be both methods should print 0 or false. What have I missed?
>

What are you expecting the print of true and false to produce?
Also, var is deprecated in PHP5.

Try this class to see what is really happening.
<?php
class Test {
private $testBool;

public function __construct($testBool) {
printf("Test constructed with testBool = %s\n", $testBool ? 'true' :
'false');
}
}

$testing = new Test(true);
$testing = new Test(false);
?>

-david-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация