473,386 Members | 1,908 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Bug with array declaration in class

Hi,

Can someone confirm this problem:

This works:

var $x = array(
"x" => "x".
"y",
"y" => "a".
"b"
);
}

var_dump($x);
But this doesn't work:

class g{
var $x = array(
"x" => "x".
"y",
"y" => "a".
"b"
);
}

$g = new g();

var_dump($g->x);

It throws

Parse error: parse error, expecting `')'' in x.php on line 5
I know I have an outdated version of PHP (4.3.2), but it is compiled
with a special MSSQl extension and I cannot seem to compile the patch
with 4.3.3 and 4.3.4. The patch reads the milliseconds for dates.
There's a workaround, but it would involve heaps of testing again.

Just wanted to see, if its worth going to a different version.

Jochen


--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #1
5 2304

"Jochen Daum" <jo*********@cabletalk.co.nz> wrote in message
news:a2********************************@4ax.com...
Hi,

Can someone confirm this problem:

<snip initialisation in declaration>

As a workaround, initialise it in the constructor.

class g{
var $x;

function g() {
$this->x = array(
"x" => "x".
"y",
"y" => "a".
"b"
);
}
}

Garp
Jul 17 '05 #2
Hi Garp,

On Tue, 20 Jul 2004 05:14:47 GMT, "Garp" <i_**@home.now> wrote:

"Jochen Daum" <jo*********@cabletalk.co.nz> wrote in message
news:a2********************************@4ax.com.. .
Hi,

Can someone confirm this problem:

<snip initialisation in declaration>

As a workaround, initialise it in the constructor.


Cheers, so you have the same problem on which PHP version?

Jochen
--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #3
Jochen Daum wrote:
Cheers, so you have the same problem on which PHP version?


This is not really a "problem" with PHP4, but just how it was designed.
Please read:

http://www.php.net/manual/en/language.oop.php

especially these examples:

<?php
class Cart {
/* None of these will work in PHP 4. */
var $todays_date = date("Y-m-d");
var $name = $firstname;
var $owner = 'Fred ' . 'Jones';
/* Arrays containing constant values will, though. */
var $items = array("VCR", "TV");
}

/* This is how it should be done. */
class Cart {
var $todays_date;
var $name;
var $owner;
var $items = array("VCR", "TV");

function Cart() {
$this->todays_date = date("Y-m-d");
$this->name = $GLOBALS['firstname'];
/* etc. . . */
}
}
?>

Just like Garp suggested.
Jul 17 '05 #4
Hi,

On Tue, 20 Jul 2004 05:24:50 GMT, Zurab Davitiani <ag*@mindless.com>
wrote:
Jochen Daum wrote:
Cheers, so you have the same problem on which PHP version?


This is not really a "problem" with PHP4, but just how it was designed.
Please read:

http://www.php.net/manual/en/language.oop.php

Right. Good Point.
Jochen
--
Jochen Daum - Cabletalk Group Ltd.
PHP DB Edit Toolkit -- PHP scripts for building
database editing interfaces.
http://sourceforge.net/projects/phpdbedittk/
Jul 17 '05 #5

"Jochen Daum" <jo*********@cabletalk.co.nz> wrote in message
news:m7********************************@4ax.com...
Hi,

On Tue, 20 Jul 2004 05:24:50 GMT, Zurab Davitiani <ag*@mindless.com>
wrote:
Jochen Daum wrote:
Cheers, so you have the same problem on which PHP version?


This is not really a "problem" with PHP4, but just how it was designed.
Please read:

http://www.php.net/manual/en/language.oop.php

Right. Good Point.


Yeah, what Zurab said. Hope you solved your problem anyway.

Garp
Jul 17 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Jeff Williams | last post by:
This doesn't compile: const char** ids = { "aaa", "bbb", "ccc" }; I hope the above illustrates what I am trying to do, if it is possible, what
4
by: Eric A. Johnson | last post by:
For the following code: ' return String representation of CTriangleShape Public Overrides Function ToString() As String ' use MyBase reference to return CShape String Return...
24
by: Michael | last post by:
Hi, I am trying to pass a function an array of strings, but I am having trouble getting the indexing to index the strings rather than the individual characters of one of the strings. I have...
3
by: garyusenet | last post by:
Hello everyone I hope you are having a good evening. This evening I made a method that allows me to find the process id's of running processes of a given 'friendly name' - using...
17
by: =?Utf-8?B?U2hhcm9u?= | last post by:
Hi Gurus, I need to transfer a jagged array of byte by reference to unmanaged function, The unmanaged code should changed the values of the array, and when the unmanaged function returns I need...
9
by: herobeat | last post by:
Hi all, I'm having a hell of a time with declaring a struct to hold some binary data I'm trying to read from some files on disk. What I would like to do is something like this: public struct...
8
by: fauxanadu | last post by:
Hello: I've been working on an assignment and I have hit a stumbling block pertaining to an array of pointers. If I am correct in my assumptions, the array struct animal* zoo should have...
4
by: kungfuelmosan | last post by:
Hey guys, Im just getting into c++ at the moment so please bare with me Basically i need to declare a vector<stringstringArray(50) inside a class, however by doing so i am getting the following...
12
by: lee.crabtree | last post by:
In C#, an array marked 'readonly', as in: public readonly bool array = new bool; would allow individual members of the array to be modified while protecting the array reference itself from...
15
by: mdh | last post by:
May I ask. If an array is defined , not as a static, but outside of a function, is there any guarantee as to the contents of each element? Thanks.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.