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

Your name:

Reply:


Posted by Greg on 10/20/05 09:14

"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.

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

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