PHP snippet stops working after upgrade to 1.4 if custom field is empty
Posted: 19 December 2005 06:59 AM   [ Ignore ]  
Grad Student
Avatar
Rank
Total Posts:  69
Joined  09-20-2004

I use the following php code to calculate a 15% plus to a buy price of a hotel room:

<?php ($rest = round (({price_tripple_luxury_03}*1.15), 2); echo $rest; ?>

where {price_tripple_luxury_03} is the short name of a custom entry field.

If {price_tripple_luxury_03} is not empty, the php renders fine.
However if {price_tripple_luxury_03} is empty, i get the following error:

Parse error: parse error, unexpected ‘*’ in /kunden/xxxxxxxxxxx/toursys/eeengine/core/core.functions.php(569) : eval()‘d code on line 262

In EE 1.3.2 everything was fine. No parse error.
I’m getting this error since i upgraded to EE 1.4.

The (test)template:


<html>
<
body>
{exp:weblog:entries cache="yes" refresh="30"  weblog="hotels" rdf="off"}
<?php
($rest = round (({price_tripple_luxury_03}*1.15), 2); echo $rest; ?>
{
/exp:weblog:entries}
</body>

</
html>

Php is allowed in this template and “PHP Parsing Stage” is set to “Output”.

Profile
 
 
Posted: 19 December 2005 08:32 AM   [ Ignore ]   [ # 1 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23744
Joined  05-20-2002

I’ll have to think on why it changed- but try adding a check:

<?php
$rest
= '{price_tripple_luxury_03}';
if (
$rest != '') { $rest = round (($rest*1.15), 2); echo $rest; } ?>

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
Posted: 19 December 2005 08:47 AM   [ Ignore ]   [ # 2 ]  
Grad Student
Avatar
Rank
Total Posts:  69
Joined  09-20-2004

That works, thank you.
But still, isn’t it strange that behavior?
That it worked in EE 1.3.2 but not in EE 1.4?
Nevertheless, thank you.

Profile
 
 
Posted: 19 December 2005 08:53 AM   [ Ignore ]   [ # 3 ]  
Moderator
Avatar
RankRankRankRankRankRankRank
Total Posts:  23744
Joined  05-20-2002

Yea- I’m trying to figure it out.  I think a few things were changed in how empty/nulls etc were entered into the db to accommodate different versions of php- so that might have something to do with it.  Basically looks like before, rest = 0*whatever in the case of an empty- which would be fine.  Now, maybe it’s rest = *whatever for an empty- thus the result looks like an encapsulated string.

Er- anyway, that’s what looks like is happening, and I suspect it may have to do with db defaults.  Maybe.

 Signature 

AKA rob1

Help Request TipsPro Network

Profile
 
 
   
 
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1149, on July 16, 2007 09:33 AM
Total Registered Members: 66394 Total Logged-in Users: 23
Total Topics: 84723 Total Anonymous Users: 22
Total Replies: 454718 Total Guests: 198
Total Posts: 539441    
Members ( View Memberlist )