array as class property question

This is a discussion on array as class property question within the PHP Language forums, part of the PHP Programming Forums category; Hi, I am using PHP 4 with classes but I have come across a slight problem... I can't declare ...


Go Back   Usenet Forums > PHP Programming Forums > PHP Language

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-25-2005
Julian
 
Posts: n/a
Default array as class property question

Hi,

I am using PHP 4 with classes but I have come across a slight problem...
I can't declare an array as a property of a class, ie,

class clTest
{
var $a[];

clTest()
{
// ...some stuff here...
}

DoAdd($name, $content)
{
$this->a[] = array("name" => $id, "content" => $content);
}
}

This produces the error,
Parse error: parse error, expecting `','' or `';'' in
/srv/www/htdocs/test/table.php on line 10

line 10 is the "var $a[]".

Am I missing something out or doesn't PHP4 allow arrays as properties?

Julian
Reply With Quote
  #2 (permalink)  
Old 03-25-2005
Erwin Moller
 
Posts: n/a
Default Re: array as class property question

Julian wrote:

> Hi,
>
> I am using PHP 4 with classes but I have come across a slight problem...
> I can't declare an array as a property of a class, ie,
>
> class clTest
> {
> var $a[];


$a = array();

<snip>

> Am I missing something out or doesn't PHP4 allow arrays as properties?


Yes PHP does allow that. :-)
Allthough most say 'hashed array' or something like that instead of
properties. (Do you come from Macromedia lingo? ;-) )


>
> Julian


Hope that helps.

Regards,
Erwin Moller

Reply With Quote
  #3 (permalink)  
Old 03-25-2005
Alvaro G. Vicario
 
Posts: n/a
Default Re: array as class property question

*** Julian escribió/wrote (Fri, 25 Mar 2005 11:55:33 +0000):
> var $a[];


var $a[]='foo';

or

var a$;

or

var $a=array('foo');

or

var $a=array();



--
-+ Álvaro G. Vicario - Burgos, Spain
+- http://www.demogracia.com (la web de humor barnizada para la intemperie)
++ No envíes tu dudas a mi correo, publícalas en el grupo
-+ Do not send me your questions, post them to the group
--
Reply With Quote
  #4 (permalink)  
Old 03-25-2005
Julian
 
Posts: n/a
Default Re: array as class property question

Thanks, it now works.

> (Do you come from Macromedia lingo? ;-) )


No, I'm from a C/C++ background but thought I'd give PHP a go. The
"properties" is the term used in my PHP reference book.

Regards,
Julian
Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT +1. The time now is 10:42 AM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0