|
Posted by Stefan Rybacki on 10/20/05 13:22
Greg wrote:
> "Bob Hartung" <rwhart@mchsi.com> wrote in message
> news:ZWD5f.444928$x96.220186@attbi_s72...
>
>>Hi all,
>> I am trying to get going with oop in php. This little script prints
>>nothing to the page.
>>
>>
>><?php
>> // define classtest.php
>>
>> class Test
>> {
>>
>> var $lname = "Smith" ;
>>
>> function get()
>> {
>> return $lname ;
>> } // end of function get()
>>
>> } // end of class test
>>
>> // body of code
>>
>> $whyme = new Test ;
>> echo $whyme->get() ;
>>
>>?>
>>
>>All help appreciated. AFAIK this should work. PHP 5 & Apache
>>
>
>
> I'm a class newbie as well, but I think I see the problem. the last section
> of cod you have, after //body of code should be in another document that
> refferences the class.php page. So your class would be the functions, and on
> a seperate page you include the class, then refference it like you did
> above. and I think it should read:
>
> $whyme = &new Test;
> echo $whyme->get();
>
> Hope that made sense.
And function get() should look like this:
function get() {
return $this->lname;
}
Regards
Stefan
>
> Greg
>
>
Navigation:
[Reply to this message]
|