A weird problem / bug with concatenation operator in a class

From: Date: Fri, 01 Feb 2002 22:27:46 +0000
Subject: A weird problem / bug with concatenation operator in a class
Groups: php.general 
Request: Send a blank email to php-general+get-83205@lists.php.net to get a copy of this message
Yesterday I presented this problem to a local usergroup... // the following lines are contained in a class // although I am echoing the value of $age from within the class // this is only for testing during development. // $age will be assigned to [$this->age_Range] later in the code $age = " AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5)<RIGHT(dob,5))"; $age .= " BETWEEN '$this->minAge' AND '$this->maxAge')"; echo $age."<br>"; Output of the echo statement looks exactly like this... AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5)<RIGHT(dob,5)) ----------------------------------------------------------------------------------------------- Here is what I found: Now, from the above if I add white space between "...)<R..." like this "...) < R..." everything works! The revised assignment looks like this: $age = " AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5) < RIGHT(dob,5))"; $age .= " BETWEEN '28' AND '42')"; And echoes: AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5)<RIGHT(dob,5))BETWEEN '28' AND '42') ----------------------------------------------------------------------------------------------- If you run the following code, you will see what I mean. I found this to be the case with PHP 4.0.2 on Windows NT 4.0 and with PHP 4.0.6 on Linux. At one point I found that echo of $age from outside the class returned the proper value regardless of white space, now I can not re-create this. The behavior would appear to be the same regardless of where you echo the var from. For what it's worth... Kevin --------------------------------------------------------- <?PHP /*+------------------------------------------+ |File: testclass.cls.php | |By: Kevin Koons | |On: Friday, February 01, 2002 11:34:41 AM | +------------------------------------------+*/ $myProfile = new profile; $sql = $myProfile->profile1(); echo "<B>The value of [\$age] returned by</B> \$myProfile->profile1()<br><hr><br>".$sql."<br><hr><br><br><br>"; echo "<B>called from class profile using</B> echo \$myProfile->age_Range<br><hr><br>".$myProfile->age_Range."<br><hr><br><br><br>"; $sql = $myProfile->profile2(); echo "<B>The value [\$age] returned by</B> \$myProfile->profile2()<br><hr><br>".$sql."<br><hr><br><br><br>"; echo "<B>called from class profile using</B> echo \$myProfile->age_Range<br><hr><br>".$myProfile->age_Range."<br><hr><br><br><br>"; class profile { var $age_Range; var $minAge = 28; var $maxAge = 42; Function profile1() { // orig code, no white space $age = " AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5)<RIGHT(dob,5))"; $age .= " BETWEEN '$this->minAge' AND '$this->maxAge')"; $this->age_Range = $age; echo "<B>Echoed from IN class Profile, no white space</B><br><hr><br>"; echo $this->age_Range."<br><hr><br><br><br>"; Return ($age); } Function profile2() { // added white space between "...) < RIGHT..." $this->age_Range = " AND ((YEAR(CURRENT_DATE)-YEAR(dob)) - (RIGHT(CURRENT_DATE,5) < RIGHT(dob,5))"; $this->age_Range .= " BETWEEN '$this->minAge' AND '$this->maxAge')"; echo "<B>Echoed from IN class Profile, white space added</B><br><hr><br>"; echo $this->age_Range."<br><hr><br><br><br>"; Return ($age); } } ?>

« previous php.general (#83205) next »