php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #37880 Cannot initialize multiline associative array in declaration portion of a class
Submitted: 2006-06-21 23:18 UTC Modified: 2006-07-18 11:27 UTC
From: cuervo_4762 at yahoo dot com Assigned: colder (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.1.4 OS: Linux
Private report: No CVE-ID: None
 [2006-06-21 23:18 UTC] cuervo_4762 at yahoo dot com
Description:
------------
I cannot seem to initialize a multi-line assoc array in the declaration part of a class.  The work around I am using is to do it in the constructor.  If this is the normal behavior it problaly should be stated in the manual.

thanks
frank

Reproduce code:
---------------
<?php
class RDBMSLoginDataSource {
    
    private $_dsn;
    private $_mdb2 = 2;
    
    private $_sql = array(
'isUserLocked'=>"SELECT users.is_locked FROM users where ".
                "user_name='$user' LOCK IN SHARE MODE",
'userLogin'   =>"SELECT users.user_name,COUNT(*) FROM " .
                "users WHERE users.user_name='$user' && ".
                "users.pass='$pass' GROUP BY " .
                "users.user_name LOCK IN SHARE MODE"
                          );
}

?>

Expected result:
----------------
na

Actual result:
--------------
Parse error: syntax error, unexpected '.', expecting ')' in /home/fmadero/public_html/classes/RDBMSLoginDataSource.php on line 8


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-22 19:05 UTC] tony2001@php.net
Reclassified as docu problem.
 [2006-06-22 21:17 UTC] colder@php.net
Class members' default values can only be scallar "fixed" values.

Here is some assignations considered "dynamic" and thus invalid:

public $var = 1+2;
public $var = $anothervar;
public $var = <<<EOD
blabla
EOD;
public $var = 'foo'.'bar';
public $var = myFunction();

This should indeed be properly documented, I'll provide a patch ASAP.
 [2006-07-18 11:27 UTC] colder@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.


http://patches.colder.ch/oop5-basic-r1.16.patch?markup
 [2020-02-07 06:11 UTC] phpdocbot@php.net
Automatic comment on behalf of colder
Revision: http://git.php.net/?p=doc/en.git;a=commit;h=1f6a127f33117c26e1e1477f666f331f226de3f2
Log: Fix #37880 (members' default value)
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 09:01:33 2025 UTC