News for hackers. Stuff that matters.
Re:Modern PHP by lekevicius on Sunday March 27, 2022 @11:07AM (#30820794)
Does any other language require to use a special notation, similar to PHP’s “$”, any time a variable is referenced? I can only think of CSS, using “--“.
Re:Modern PHP by tyingq on Sunday March 27, 2022 @11:33AM (#30821020)
These all use sigils on variables in one way or another: Unix Shells, AWK, Perl, Ruby, Tcl, Basic, PowerShell, DOS batch scripts
Re:Modern PHP by markkrj on Sunday March 27, 2022 @12:12PM (#30821400)
-AWK
Re:Modern PHP by tyingq on Sunday March 27, 2022 @01:30PM (#30822115)
Ah, yeah, I suppose it's more of a "field operator" for things like $1, $2, etc.
Re:Modern PHP by toastal on Sunday March 27, 2022 @11:16AM (#30820868)
This is called a “sigil”
Re:Modern PHP by krapp on Sunday March 27, 2022 @11:08AM (#30820802)
PHP got that from Perl AFAIK. Bash does it too, and TCL.
Re:Modern PHP by chubot on Sunday March 27, 2022 @11:43AM (#30821116)
I'm pretty sure that historically shell is the common influence of PHP, Perl, and Tcl.

PHP also inherits shell's here doc syntax, e.g. <<EOF . Not sure if Perl has that.

Actually PHP started out as a bunch of cgi-bin scripts, if I recall. It was very much "a shell for the web".

It kind of annoys me that they all require $ on the left, whereas shell only requires it on the right, which somehow makes more sense to me, e.g.

    a=$b  # shell

    $a = $b  # PHP and I think Perl
Re:Modern PHP by pweezy on Sunday March 27, 2022 @11:49AM (#30821181)
> It kind of annoys me that they all require $ on the left, whereas shell only requires it on the right

Interesting - it makes it look like Bash uses $ to “read” from the variable, while in PHP/Perl $ only indicates that the rest of the symbol _is_ a variable.

Re:Modern PHP by tyingq on Sunday March 27, 2022 @11:51AM (#30821205)
>>PHP also inherits shell's here doc syntax, e.g. <<EOF . Not sure if Perl has that.

It does.

>>It kind of annoys me that they all require $ on the left

Larry Wall says he went that direction to make namespace clashing between $dog, @dog, %dog, and "sub dog {}" (scalar, array, hashtable, function) a non-issue.

http://www.wall.org/~larry/natural.html ("Disambiguation")

Re:Modern PHP by ZeroGravitas on Sunday March 27, 2022 @11:44AM (#30821130)
Ruby also has $ for global variables, which I assume it also got via Perl. And @ for instance variables, and @@ for class variables.
Re:Modern PHP by TylerE on Sunday March 27, 2022 @09:59PM (#30826253)
It's much worse in perl, because it changes based on how you're using it. E.g. an array vs an element of an array.
Re:Modern PHP by Eric_WVGG on Sunday March 27, 2022 @12:02PM (#30821294)
Back in the eighties, my father taught me that the “$” character in BASIC meant “string,” so when I later picked up PHP in ‘98 I mentally thought of $someVar as “string-someVar” (regardless of the actual type, which was of course no problem for PHP), kept that habit for well over a decade… I think it was partially my self-disgust over such silly and technically incorrect thinking that led me to bail for Node as soon that was a feasible alternative.

The dollar sign does kinda look like a loose piece of shoestring, though

Re:Modern PHP by agumonkey on Sunday March 27, 2022 @01:52PM (#30822324)
I can't remember all details but in Lisp in small pieces, author describes variable handling with a table { creation, reference/access, modification, [deletion] }

with each category had it's own optional syntax, many language will avoid this through context in which the symbol is, thus (+ a 1) equates (+ (deref a) 1), but he meant that it was a choice and not an obligation and some systems used $ or other syntactic constructs.

Re:Modern PHP by todotask on Sunday March 27, 2022 @11:17AM (#30820877)
It's more than what most of us know, Rosetta Code is a good way to find. https://rosettacode.org/wiki/Variables
Re:Modern PHP by ainar-g on Sunday March 27, 2022 @11:12AM (#30820834)
krapp has already mentioned the Unix stuff. BASIC had a thing with a $ at the end of a string variable, iirc. Windows' CMD.EXE used %VAR% notation (and later !VAR! notation).
Re:Modern PHP by dylan604 on Sunday March 27, 2022 @11:29AM (#30820989)
jquery, lodash, etc all added prefixes (or TIL: sigil) of somesort
Re:Modern PHP by nobleach on Sunday March 27, 2022 @11:48AM (#30821162)
jQuery's $ and lodash's _ are not prepended to a symbol to denote a variable. Both are objects actually. In the case of jQuery, $ === jQuery (the root jQuery object). The case that the parent is talking about is PHP's requirement that all variables are denoted as such `$variable_name`. (Perl and Bash also do this)
Re:Modern PHP by dylan604 on Sunday March 27, 2022 @01:05PM (#30821864)
i forget that's what's actually being done under the hood.
Re:Modern PHP by graftak on Sunday March 27, 2022 @11:51AM (#30821207)
That’s just (part of) the variable name and not really the same.
Re:Modern PHP by throw_m239339 on Sunday March 27, 2022 @12:52PM (#30821749)
> jquery, lodash, etc all added prefixes (or TIL: sigil) of somesort

This is false they are not sigils at all. _ and $ are legal variable names in Javascript.

Re:Modern PHP by icedchai on Sunday March 27, 2022 @11:56AM (#30821235)
Basic uses them at the end for string variables... A$...
Re:Modern PHP by jansommer on Sunday March 27, 2022 @11:29AM (#30820983)
jsoniq uses the same notation https://www.jsoniq.org/