| | |
How can I declare an array as class variable?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jul 2006
Posts: 136
Reputation:
Solved Threads: 0
Hello,
How can I declare an array as a class variable? For example I can do:
But how can I make the following work?
How can I declare an array as a class variable? For example I can do:
PHP Syntax (Toggle Plain Text)
<?php class test { private $name = 'john'; public function getName() { return $this->name; } } ?>
But how can I make the following work?
PHP Syntax (Toggle Plain Text)
<?php class test { private $name = array(); private $name[] = 'john'; private $name[] = 'jenny'; public function getName() { return $this->name; } } ?>
you need to use a constuctor
PHP Syntax (Toggle Plain Text)
<?php class test { var $name = array(); //this function used to make class PHP4 compatible function test() { $this->__construct(); } function __construct() { $this->name = array('john','jenny'); } function getName() { return $this->name; } } ?>
![]() |
Similar Threads
- Tutorial: Understanding ASP classes (ASP)
- Differences Between Java and C/C++ (C++)
- Instantiating an Object of a Class Confusion (Java)
- Stack conversion (C++)
- Applet / Array help (Java)
- Homework HELP!!! (Java)
- Need help passing a multi-dimensional array (C++)
- Help with Class, stuck. (C++)
- Don't know how to proceed with my program. (Java)
- How do I create a program using an Array ? (C++)
Other Threads in the PHP Forum
- Previous Thread: File upload problem
- Next Thread: inbox
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date directory display download dynamic echo email encode error fcc file files folder form forms function functions google howtowriteathesis href htaccess html image include insert integration ip java javascript joomla limit link login loop mail menu methods mlm mod_rewrite multiple multipletables mysql oop open parse paypal pdf php problem provider query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure syntax system table template tutorial update upload url validation validator variable video web xml youtube






