Comparison loop returns true twice without altering values

Author Message

Eirik Alfstad Johansen

Monday 21 February 2005 11:02:25 am

Hi,

Could someone please explain to me why the following code:

{let options=hash('all', 'All weekdays', 1, 'Monday', 2, 'Tuesday', 3, 'Wednesday', 4, 'Thursday', 5, 'Friday', 6, 'Saturday', 0, 'Sunday')}
	{let selected_option='all'}
	        {section name=Child loop=$options}
			{$:key}: {eq($:key, $selected_option)}<br />
		{/section}
	{/let}
{/let}

...returns the following output:

 all: 1
1:
2:
3:
4:
5:
6:
0: 1

As you might guess, I was expecting only the first iteration to evaluate to true.

Thanks in advance !

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Kristian Hole

Wednesday 23 February 2005 6:04:51 am

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Eirik Alfstad Johansen

Wednesday 23 February 2005 7:11:48 am

Hi Kristian,

Thanks for confirming. I've posted the bug here: http://ez.no/bugs/view/6250

Sincerely,

Eirik Alfstad Johansen
http://www.netmaking.no/

Kristian Hole

Wednesday 23 February 2005 8:15:51 am

Hi again!

I've closed the bug. The reason for the bug:

This is because of the way PHP works, and the way it converts strings to integers and visa versa. The resolution is to not to compare integers to strings (or to not to compare strings with the number 0).

A resolution to your problem is either to use 7 or -1 as sunday, or use a number for "any".

Kristian

http://ez.no/ez_publish/documenta...tricks/show_which_templates_are_used
http://ez.no/doc/ez_publish/techn...te_operators/miscellaneous/attribute

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 22:30:11
Script start
Timing: Jan 18 2025 22:30:11
Module start 'layout'
Timing: Jan 18 2025 22:30:11
Module start 'content'
Warning: PHP: E_WARNING Jan 18 2025 22:30:12
DOMDocument::loadXML(): Opening and ending tag mismatch: literal line 2 and paragraph in Entity, line: 8 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Warning: PHP: E_WARNING Jan 18 2025 22:30:12
DOMDocument::loadXML(): Opening and ending tag mismatch: paragraph line 2 and section in Entity, line: 12 in /home/ze/public_html/share.se7enx.com/kernel/classes/datatypes/ezxmltext/ezxmloutputhandler.php on line 174
Timing: Jan 18 2025 22:30:12
Module end 'content'
Timing: Jan 18 2025 22:30:12
Script end

Main resources:

Total runtime1.1422 sec
Peak memory usage4,096.0000 KB
Database Queries60

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0054 589.6016152.6563
Module start 'layout' 0.00540.0030 742.257839.5078
Module start 'content' 0.00841.1327 781.7656555.2578
Module end 'content' 1.14110.0010 1,337.023412.6172
Script end 1.1422  1,349.6406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00300.2633160.0002
Check MTime0.00130.1117160.0001
Mysql Total
Database connection0.00070.058510.0007
Mysqli_queries1.087995.2496600.0181
Looping result0.00060.0562580.0000
Template Total1.110997.320.5554
Template load0.00200.177320.0010
Template processing1.108897.080120.5544
Template load and register function0.00010.006810.0001
states
state_id_array0.00090.077410.0009
state_identifier_array0.00100.091920.0005
Override
Cache load0.00180.1533230.0001
Sytem overhead
Fetch class attribute can translate value0.00060.053820.0003
Fetch class attribute name0.00130.113560.0002
XML
Image XML parsing0.00100.083920.0005
class_abstraction
Instantiating content class attribute0.00000.001580.0000
General
dbfile0.00080.0730220.0000
String conversion0.00000.000840.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
4content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
5content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
2content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 17
 Number of unique templates used: 6

Time used to render debug report: 0.0001 secs