Doc #62997 [Opn]: Section on variables: explain $1 is always literal

From: Date: Mon, 03 Sep 2012 02:57:43 +0000
Subject: Doc #62997 [Opn]: Section on variables: explain $1 is always literal
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-8804@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=62997&edit=1 ID: 62997 Updated by: aharvey@php.net Reported by: php at richardneill dot org Summary: Section on variables: explain $1 is always literal Status: Open Type: Documentation Problem Package: Documentation problem Operating System: Linux PHP Version: Irrelevant Block user comment: N Private report: N New Comment: It's deliberate in the sense that it's not a valid variable name (it's kind of hinted at in the String Parsing section, if not explicitly stated), but I'm not sure that it's a code pattern that we want to be pushing, really: it's probably simpler for new developers to just understand that $ is magic in double quoted strings and push them towards single quoted strings in this case, and let them work out the corner cases later if need be. Does anyone else on the doc team have any thoughts? Not sure whether to Won't Fix this or not. Previous Comments: ------------------------------------------------------------------------ [2012-09-02 14:10:57] php at richardneill dot org Description: ------------ In something like pg_query_params(), it is OK to use eg $sql = "select * from table where id=$1" In other words, because variable names cannot begin with numbers, constructs such as $1, $2 etc are literal, even within double-quotes. This is actually quite helpful - and it seems to be deliberate (at any rate, no errors appear in logfile). I think the documentation should make it clearer. Test script: --------------- echo 'You owe me $100'; echo "You owe me \$100"; echo "You owe me $100"; all produce the same output. The 3rd of these is (to me) rather surprising, though useful, and isn't documented, either in the variable-naming or the double-quoted string sections. It should also appear in the pg_query_params() docs. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=62997&edit=1

« previous php.doc.bugs (#8804) next »