Reply to Re: Class newbie - why doesn't this work?

Your name:

Reply:


Posted by Bob Hartung on 10/20/05 14:08

Stefan,
Thanks for the response but:
1. It should not matter wether I use
function get() {
...
}

or
function get()
{
...
}

Multiple references mix the two styles as in C++.

2. The classes should not have to be declared in a separate file.
This is typical in large projects, but again as in C++ the class can be
declared before the main() code unless PHP is very different than
any other programming metaphor that I can find.

So I am still looking for an answer.

Thanks again,

Bob

Stefan Rybacki wrote:
> 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
>>
>>

[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

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