Reply to Re: objects of MyClass in array?

Your name:

Reply:


Posted by Rik Wasmus on 01/07/08 23:16

On Mon, 07 Jan 2008 23:55:05 +0100, devloop <andrea2004@gmx.de> wrote:

> Hi,
> I am a JAVA developer who just started with php5 (on a WAMPP with
> php5.2.1).
>
> I´ve the following problem with a little class (I wanted to put
> objects into the array later but even with simple strings it doesn´t
> work!!!!!!!!!).
>
> The output doesn´t show any letters/strings when I call the method
> toHtml().
>
> file MyClass.inc:
> -----------------------
> <?php
> class MyClass{
> private $my_string_array=array();
>
> public function __construct(){
>
> $my_string_array[]="A";

You should use:
$this->my_string_array[] = 'A';
$my_string_array is only a variable in the scope of the function and will
be discarded as soon as the function finishes.

> optional when problem solved:
>
> How do you have to write MyClass when the array´s elemets are objects
> of a class (e.g. MyOtherClass that one I still have to write it)?

Just add an object to the array instead of a string, makes no difference
(allthough you may want to look at the Iterator interface)
--
Rik Wasmus

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация