Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

is_int bug?

  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
3 years 3 months ago #226234 by Jmantysalo
is_int bug? was created by Jmantysalo
From the server command line
echo '<?php if(is_int(strpos("a", "b"))) print "y"; else print "n"; ?>' | php
prints "n". In a question text
{if(is_int(strpos("a", "b")), "y", "n")}
gives string "y". Is this a bug, or have I understood something wrong?

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #226235 by Joffm
Replied by Joffm on topic is_int bug?
Hi,
from the LimeSurvey point of view the result is fine.
strpos("a", "b") -> 0 -> "not found"
And is_int(0) is TRUE.

But you will get the same result here
strpos("a", "a") -> 0 -> "found at index 0"

In my opinion the problem is that LimeSurvey does not support "===". Therefore "strpos" can't distinguish between "0 as 'not found'" and "0 as 'found at index 0'"
In all my examples where I use "strpos" I prepend the string by a character like "#" that the first index that can be found at least has index "1".

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
3 years 3 months ago #226236 by Jmantysalo
Replied by Jmantysalo on topic is_int bug?
Nope, that's not the problem.

x {strpos("a", "b")} y xx {strpos("a", "a")} yy

gives "x y xx 0 yy". But the fix works still and I have already sent that to the person who had this problem.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
3 years 3 months ago #226239 by Joffm
Replied by Joffm on topic is_int bug?
Yes, but here
x {intval(strpos("a", "b"))} y xx {intval(strpos("a", "a"))} yy
you get
x 0 y xx 0 yy

and you're back to your first question about "is_int".

So, avoid to get a positive result of "0".

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless
The following user(s) said Thank You: Jmantysalo

Please Log in to join the conversation.

  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
3 years 3 months ago #226240 by Jmantysalo
Replied by Jmantysalo on topic is_int bug?
True. To confirm: I guess we agree that there is a bug in is_int and I can make a bug report?
The following user(s) said Thank You: DenisChenu

Please Log in to join the conversation.

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • LimeSurvey Community Team & Official Partner
  • LimeSurvey Community Team & Official Partner
More
3 years 3 months ago #226243 by DenisChenu
Replied by DenisChenu on topic is_int bug?

True. To confirm: I guess we agree that there is a bug in is_int and I can make a bug report?
 
Complex to fix ;)

Else about strpos : i always use (in LimeSurvey) {strpos(join("#",MyVar),"a")} then just > 0 ;)

Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member. - Professional support - Plugins, theme and development .
I don't answer to private message.

Please Log in to join the conversation.

  • Jmantysalo
  • Jmantysalo's Avatar Topic Author
  • Offline
  • Platinum Member
  • Platinum Member
More
3 years 3 months ago - 3 years 3 months ago #226244 by Jmantysalo
Replied by Jmantysalo on topic is_int bug?

Complex to fix ;)

 
True, but let's try at least. bugs.limesurvey.org/view.php?id=17950
Last edit: 3 years 3 months ago by Jmantysalo.

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose