Deref Anywhere is Major Break in Backward Compatibility

Things you’d like to miss in the future...
Forum rules
You might want to read this if you're looking for priority service

:info: Please Include The Following Information
1) Your XYplorer Version (e.g., v28.00.0801)
2) Your Windows Version (e.g., Win 11)
3) Your Screen Scaling Percentage (e.g., 125%).

:info: Use Your Profile Or Signature
We strongly recommend adding your Windows Version and Screen Scaling Percentage to the Location field in your Profile or to your Signature. That way, you only have to type them once, and we won't have to search for that vital information.

:info: How To Attach Images
When attaching an Image, please use the Attachment tab at the bottom of your post and click "Add files".
FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Deref Anywhere is Major Break in Backward Compatibility

Post by FluxTorpedoe »

Hi'

@Don
Not really a :bug: but a disrupting side-effect has been introduced in the use of the Like operator with variables (because of changes with dereferenced operators, I presume):
::$b="b"; if ("abc" Like "*$b*"){msg "ok";}
doesn't work anymore, the * before $b must now be escaped:
::$b="b"; if ("abc" Like "**$b*"){msg "ok";}

I discovered this while searching why my implementation of Marco's Everything script wasn't working with an updated XY — so most of you probably had empty results when you tried it.

Don't know how that should be handled... Good luck with that! :)

Have a nice day, 8)
Flux

admin
Site Admin
Posts: 67280
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: [β] Everything in XYplorer — Rev. 0.94 / 2014/07/09

Post by admin »

I guess you have to do this now:

Code: Select all

::$b="b"; if ("abc" Like "*".$b."*"){msg "ok";}

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: [β] Everything in XYplorer — Rev. 0.94 / 2014/07/09

Post by PeterH »

admin wrote:I guess you have to do this now:

Code: Select all

::$b="b"; if ("abc" Like "*".$b."*"){msg "ok";}
OK:

Code: Select all

::$b="b"; if ("abc" Like "*"."$b*"){msg "ok";}
should work to. :D

While FluxTorpedoes solution only works by chance: as $b doesn't contain a defined variable name, *$b is resolved by the contents of $b (and the * is 'ignored') :P

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by TheQwerty »

Guys this breaks a hell of a lot more than just the Like operator.

'*$var' is going to be common in regular expressions, filters, renames, and anywhere else that wildcards are supported.

Looking at my own script files I have 312 lines that now need to be debugged because of this haphazardly adding dereferencing everywhere. :cry:

admin
Site Admin
Posts: 67280
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by admin »

Well, it's not too late. I was in doubt about this anyway, and since there is no dereferencing like this in PHP I have no model to look it up.

So, does everybody agree that dereferencing should NOT take place in Interpolation? (Interpolation means that variables that are embedded in double-quoted or unquoted strings are resolved.) I agree.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by TheQwerty »

I agree - at least until we can think of a better way to handle this.

That includes HEREDOCs correct?

admin
Site Admin
Posts: 67280
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by admin »

Yep.

FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by FluxTorpedoe »

admin wrote:So, does everybody agree that dereferencing should NOT take place in Interpolation? (Interpolation means that variables that are embedded in double-quoted or unquoted strings are resolved.) I agree.
Fine by me. :)

BTW,
admin wrote:I guess you have to do this now:

Code: Select all

::$b="b"; if ("abc" Like "*".$b."*"){msg "ok";}
That's the first thing I tried and why it took me so long to figure out the source of the dereferencing problem: it gives false positives (or am I missing something?)…
::$b="b"; if ("xyz" Like "*".$b."*"){msg "ok";} // OK
:veryconfused:

admin
Site Admin
Posts: 67280
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by admin »

:veryconfused: :shock: Guess I gotta look into this NOW... :twisted:

admin
Site Admin
Posts: 67280
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by admin »

Okay, no bug. It's caused by operator precedence. Need to add some parentheses:

Code: Select all

::$b="b"; if ("xyz" Like ("*".$b."*")){msg "ok";} // OK

FluxTorpedoe
Posts: 906
Joined: 05 Oct 2011 13:15

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by FluxTorpedoe »

Hmmm, so the "Like" operator has precedence over the "dot concatenator"…
Good to know!

BTW, thanks for being so responsive (as always)… 8)

PeterH
Posts: 2830
Joined: 21 Nov 2005 20:39
Location: DE W11Pro 24H2, 1920*1200*100% 3840*2160*150%

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by PeterH »

admin wrote:Well, it's not too late. I was in doubt about this anyway, and since there is no dereferencing like this in PHP I have no model to look it up.

So, does everybody agree that dereferencing should NOT take place in Interpolation? (Interpolation means that variables that are embedded in double-quoted or unquoted strings are resolved.) I agree.
I *don't* like it, but I see the need.
Especially inside double quotes.

But also in "unquoted strings"? They "should" not exist at all?
I'm just afraid this could make problems with other situations, as I don't know exactly how to differentiate "unquoted strings" from other situations...

admin
Site Admin
Posts: 67280
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by admin »

Unquoted strings are tolerated. I don't see particular problems with regard to dereferenciation.

TheQwerty
Posts: 4373
Joined: 03 Aug 2007 22:30

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by TheQwerty »

A possible compromise...
Add a deref interpolation SC: deref(string, [flags=0])

string should be a literal (in single quotes) to avoid interpolation of the function's input (see examples).

Flags:
0 = Interpolate derefs and then other variables.
1 = Interpolate derefs only.

Code: Select all

"Examples"
  $g = 'Hello';
  $v = '$n';
  *$v = 'world';

  echo deref('$g *$v!');      // 'Hello world!'
  echo deref('$g *v!', 1);    // '$g world!'

  // Examples of why you'll want to avoid the initial interpolation.
  echo deref("$g *$v!", 1);   // 'Hello *$n!'
                              // Became deref('Hello *$n', 1);
                              // Flag is 1, so '$n' is untouched & there is no '*$n'.

  echo deref("$g *$v!");      // 'Hello *world!'
                              // Became deref('Hello *$n');
                              // Flag is 0, there is no '*$n' so '$n' is resolved.
Since that's a new SC it shouldn't break anything - it's not as legible but it's much safer.


For HEREDOC support you introduce a new syntax '<<<*FOO' and '<<<*#FOO'. Unfortunately, this will break backwards compatibility, but I see no other way. Hopefully this won't actually affect anyone since it seems most people stick with alpha characters when naming their HEREDOCs. (I have zero matches for '<<<*'.)

Fair tradeoffs?


----

If you wanted to go even further - I know we've seen some requests for fine tuning which variables are resolved so this deref SC could really be an interpolate SC with flag:
-1 - All (default)
0 - None
1 - XY variables ('<...>')
2 - Environment variables ('%...%')
4 - Local variables
8 - Permanent variables
16 - Global variables
32 - Derefed variables.

admin
Site Admin
Posts: 67280
Joined: 22 May 2004 16:48
Location: Win8.1, Win10, Win11, all @100%
Contact:

Re: Deref Anywhere is Major Break in Backward Compatibility

Post by admin »

Wow, little overkill maybe? ;)

Post Reply