php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26448 Unable to define a variable in a class
Submitted: 2003-11-28 10:54 UTC Modified: 2004-02-03 20:16 UTC
From: hervecaussinus at yahoo dot ca Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 5.0.0b2 (beta2) OS: Windows 2000
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: hervecaussinus at yahoo dot ca
New email:
PHP Version: OS:

 

 [2003-11-28 10:54 UTC] hervecaussinus at yahoo dot ca
Description:
------------
I am not able to use the class examples in your Web site. In fact it seems that it is impossible to declare a variable when defining a class.

I am very new to PHP (3 days). Sorry if I am doing something wrong.

I look at the bug database and I also download and install the last binary (php5-win32-200311281530.zip).


Reproduce code:
---------------
<?php
class MyClass {
   $Hello = "Hello, World!\n";
}
print 1;
?>


Expected result:
----------------
Should parse and display 1 .

Actual result:
--------------
Gives this error:

Parse error: parse error, unexpected T_VARIABLE, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in c:\inetpub\wwwroot\CorePHP\6-1.php on line 3


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-28 11:31 UTC] derick@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

You need to define class variables like this:

class MyClass {
  public $Hello = \"Hello, World\\n\";
}

no bug here.
 [2003-11-28 12:01 UTC] hervecaussinus at yahoo dot ca
I test the syntax:

<?php
class MyClass {
  public $Hello = \"Hello, World\\n\";
}
print 1;
?>

and it does not work. Once again I am very sorry if I am doing something wrong (that is possible due to my short experience) but I think it is a bug (that looks strange I must admit).
 [2004-02-03 15:15 UTC] redeye at erisx dot de
Remove the Backslashes ( your string wasn't enclosed )

<?php
class MyClass {
  public $Hello = "Hello, World\n";
}
print 1;
?>
 [2004-02-03 15:36 UTC] hervecaussinus at yahoo dot ca
Thank you. I will test this again in my office.
 [2004-02-03 20:16 UTC] magnus@php.net
Leave as bogus.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Sep 11 18:01:28 2024 UTC