Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:30940 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92555 invoked by uid 1010); 14 Jul 2007 21:43:36 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 92540 invoked from network); 14 Jul 2007 21:43:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Jul 2007 21:43:36 -0000 Authentication-Results: pb1.pair.com smtp.mail=gwynne@wanderingknights.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=gwynne@wanderingknights.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain wanderingknights.org from 208.97.132.66 cause and error) X-PHP-List-Original-Sender: gwynne@wanderingknights.org X-Host-Fingerprint: 208.97.132.66 sd-green-bigip-66.dreamhost.com Linux 2.4/2.6 Received: from [208.97.132.66] ([208.97.132.66:55593] helo=postalmail-a3.g.dreamhost.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 56/BA-05977-58349964 for ; Sat, 14 Jul 2007 17:43:34 -0400 Received: from [192.168.2.197] (c-24-61-79-221.hsd1.ma.comcast.net [24.61.79.221]) by postalmail-a3.g.dreamhost.com (Postfix) with ESMTP id B35684B7E2 for ; Sat, 14 Jul 2007 14:43:30 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v752.3) Content-Transfer-Encoding: 7bit Message-ID: <8473AAB9-EFFD-475F-9BBA-B3D3B284AA8B@wanderingknights.org> Content-Type: text/plain; charset=US-ASCII; delsp=yes; format=flowed To: PHP Developers Mailing List Date: Sat, 14 Jul 2007 17:43:28 -0400 X-Mailer: Apple Mail (2.752.3) Subject: Patch to add "single-quote" heredocs From: gwynne@wanderingknights.org (Gwynne Raskind) So I was using create_function() in various ways, and I said to myself, "this would look SO much better if I could use a heredoc that acted like a single-quoted string". Then I said to myself, "Wait. I know the PHP internals. Why don't I build a new syntax into the language?" The result was a small modification of the heredoc syntax that I call "nowdoc", and it looks like this: And the output is: I see 1. I see $n. The b modifier is fully supported; a nowdoc acts exactly like a single-quoted string, save that you can embed single quotes into it. I wrote the patch for HEAD, backported it to PHP_5_2 (both fully up- to-date as of this message), and wrote a set of regression tests. The patch breaks none of the existing regression tests, and has no BC or SC breaks whatsoever, as far as I can tell. The patch can be found at . I hope to see it included in PHP 6 and 5.3, maybe even 5.2.4 or 5.2.5 since existing scripts will continue to work without modification. <<<~ was a parse error before, so anyone who used it was doing something wrong anyway. Side note: I implemented nowdocs in the parser by sharing the heredoc code and passing $ and {$ through unmodified instead of replaced. I don't understand the way the HEREDOC_CHARS regexps work well enough to write a simpler matching rule for the newdocs, but it's clear that the patch could be optimized if only I knew how, since the entire content can be parsed by a single call to zend_scan_[unicode|binary_] escape_string() rather than having to be parsed for replacements. I may look into this later, but for the moment I wanted to get what's working out there in the commmunity. -- Gwynne, Daughter of the Code "This whole world is an asylum for the incurable."