Posted by devloop on 01/07/08 22:55
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";
$my_string_array[]="B";
$my_string_array[]="C";
$my_string_array[]="D";
}
public function fill_my_array(){
$my_string_array[0]="A";
$my_string_array[1]="B";
$my_string_array[2]="C";
$my_string_array[3]="D";
}
public function toHtml(){
if( is_array($this->my_string_array))
{
echo "its an array <br>\n";
}
$x=count($my_string_array);
echo "number of elements=" . $x . "<br>\n";
echo "string0= ". $my_string_array[0] . "<br>\n";
echo "string1= ". $my_string_array[1] . "<br>\n";
echo "string2= ". $my_string_array[2] . "<br>\n";
echo "string3= ". $my_string_array[3] . "<br>\n";
}
}
?>
file test.php
-------------------
<?php
require_once("./MyClass.inc");
$s=new MyClass();
$s->toHtml();
echo "finished MyClass with constructor<br>\n";
$q=new MyClass();
$q->fill_my_array();
$q->toHtml();
echo "finished MyClass with extra fill function<br>\n";
?>
Output (as not excepted):
--------------------------------------
its an array
number of elements=0
string0=
string1=
string2=
string3=
finished MyClass with constructor
its an array
number of elements=0
string0=
string1=
string2=
string3=
finished MyClass with extra fill function
What the hell is wrong????????????????????????????????????
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)?
Please help!
[Back to original message]
|