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

Posted by Greg Scharlemann on 12/17/90 11:52

David Haynes wrote:
> Also, var is deprecated in PHP5.
Thanks!
Your test case also worked... but I'm going to make my question a
little more complicated...

That boolean value is going to be written to a MySQL database. I've set
the column to be of type Bool (which appears to turn into a
Tinyint(1)), is that the best approach? Should I use enum('true',
'false') or some other approach?

Second, since the values get screwed up when cast to a String, should I
just go around the true/false nominclature and use 1/0?

Finally, another somewhat semi-related newbie question. I come from a
java background with getter and setter methods. I modified the Test
class David created with what I thought is a getter method, however it
doesn't work... The function just prints: "()" PHP is not as straight
forward as I hoped...

<?php
class Test {
private $testBool;

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

public function getTestBool() {
return "$testBool";
}

}
$testing = new Test(true);
$testing = new Test(false);
print "testing->getTestBool() = $testing->getTestBool()";
?>

 

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

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