php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77130 Documentation error
Submitted: 2018-11-09 10:32 UTC Modified: 2018-11-09 16:17 UTC
From: clement dot barbaza at gmail dot com Assigned:
Status: Not a bug Package: Documentation problem
PHP Version: 7.2.12 OS: Mac OS 10.14.1
Private report: No CVE-ID: None
 [2018-11-09 10:32 UTC] clement dot barbaza at gmail dot com
Description:
------------
Hello,

I found an error in the documentation Strings : http://php.net/manual/en/language.types.string.php

There is a problem on the documentation :
echo "He drank some juice made of ${juice}s.";

Instead, it has to be : 
echo "He drank some juice made of {$juice}s.";


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-09 10:39 UTC] bwoebi@php.net
-Status: Open +Status: Not a bug
 [2018-11-09 10:39 UTC] bwoebi@php.net
This is valid syntax. Though you usually see the latter variant, it's just two syntaxes to express the same thing.
 [2018-11-09 10:39 UTC] sjon at Hortensius dot net
actually both are correct, so why do you think it has to be one, not the other?
 [2018-11-09 12:59 UTC] clement dot barbaza at gmail dot com
Hi,

Thank you for your quick reply!

I know there are 2 syntaxes to express the same thing, but in this case, it doesn't work :(

I simply created a file and inserted the documentation code :

<?php

$juice = "apple";

echo "He drank some $juice juice.".PHP_EOL;
// Invalid. "s" is a valid character for a variable name, but the variable is $juice.
echo "He drank some juice made of $juices.";
// Valid. Explicitly specify the end of the variable name by enclosing it in braces:
echo "He drank some juice made of ${juice}s.";

Here's the result:

php -f index.php
He drank some apple juice.
PHP Notice:  Undefined variable: juices in index.php on line 7

Notice: Undefined variable: juices in index.php on line 7
He drank some juice made of .He drank some juice made of apples.%

I hope it will help you to check this documentation error.
 [2018-11-09 16:09 UTC] cmb@php.net
Check line 7.  See https://3v4l.org/A1mQQ.
 [2018-11-09 16:17 UTC] clement dot barbaza at gmail dot com
Yes, you are entirely right.

The problem is on line 7 that corresponds at :

echo "He drank some juice made of $juices.";

It's my fault, I don't know why but I thought the comments described the line above and not the line under :(
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Wed Nov 25 09:01:23 2020 UTC