Connecting Tech Pros Worldwide Help | Site Map

array as class property question

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 17th, 2005, 12:17 PM
Julian
Guest
 
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

  #2  
Old July 17th, 2005, 12:17 PM
Erwin Moller
Guest
 
Posts: n/a
Default Re: array as class property question

Julian wrote:
[color=blue]
> 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[];[/color]

$a = array();

<snip>
[color=blue]
> Am I missing something out or doesn't PHP4 allow arrays as properties?[/color]

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

[color=blue]
>
> Julian[/color]

Hope that helps.

Regards,
Erwin Moller

  #3  
Old July 17th, 2005, 12:17 PM
Alvaro G. Vicario
Guest
 
Posts: n/a
Default Re: array as class property question

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

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
--
  #4  
Old July 17th, 2005, 12:17 PM
Julian
Guest
 
Posts: n/a
Default Re: array as class property question

Thanks, it now works.
[color=blue]
> (Do you come from Macromedia lingo? ;-) )[/color]

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
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,989 network members.