php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #32554 member variable initialization with heredoc
Submitted: 2005-04-03 07:12 UTC Modified: 2005-04-05 14:20 UTC
From: 000005 at gmail dot com Assigned:
Status: Closed Package: Documentation problem
PHP Version: 4CVS,5CVS (2005-04-03) OS: Linux 2.6/Gentoo
Private report: No CVE-ID: None
 [2005-04-03 07:12 UTC] 000005 at gmail dot com
Description:
------------
Trying to initialize a member variable using heredoc 
notation produces a compiler error:

Parse error: parse error, unexpected T_START_HEREDOC in 
/.../foo.php on line 6

Reproduce code:
---------------
<?

class foo
{
public $bar = <<<END
blah blah blah
END;
}

?>

Expected result:
----------------
The member variable $bar to be assigned "blah blah 
blah".

Actual result:
--------------
Parse error: parse error, unexpected T_START_HEREDOC in 
/.../foo.php on line 6

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-03 13:06 UTC] sniper@php.net
This is not really PHP bug but just missing documentation.
(or I just couldn't find the place where it's documented :)

You can only put static scalars as the default value.

 [2005-04-04 01:23 UTC] 000005 at gmail dot com
> This is not really PHP bug but just
> missing documentation. (or I just couldn't
> find the place where it's documented :)

I couldn't find where this is documented either.

> You can only put static scalars as the
> default value.

I am able to initialize member variables with strings using single or double quotes. Is a string a scalar?

Mainly, is there a way to initialize a member variable with a multi-line string? I think there should be.

Thanks
 [2005-04-05 14:20 UTC] vrana@php.net
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.

Thank you for the report, and for helping us make our documentation better.

"It is not allowed to use heredoc syntax in initializing class members. Use other string syntaxes instead." + example

P.S. You can initialize the member with multiline string with "first line \n second" or "first line
second".
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 18 20:01:27 2024 UTC