You are here: Re: Object of class Person could not be converted to string « PHP Programming Language « IT news, forums, messages
Re: Object of class Person could not be converted to string

Posted by gosha bine on 06/11/07 12:46

On 11.06.2007 06:46 phpCodeHead wrote:
> Code which should allow my constructor to accept arguments:
>
> <?php
> class Person {
> function __construct($name)
> {
> $this->name = $name;
> }
>
> function getName()
> {
> return $this->name;
> }
>
> function printName()
> {
> print $this->name;
> }
>
> private $name;
> }
>
> $judy = new Person("Judy") . "\n"; // <- this is line parser don't
> like
> $joe = new Person("Joe") . "\n";
>
> $judy->printName() . '<br />';
> $joe->printName() . '<br />';
> ?>
>
> Outputs:
>
> Catchable fatal error: Object of class Person could not be converted
> to string
>
> Anyone seen this before? Know why? Am I missing something here?
>
> Thanks all...
>
> Gene Kelley
> LAMP Web Developer
> bizFlowDesigns.com
>

This is a new "feature" of 5.2 - for some mystical reason they've
removed implicit object-to-string conversion. You must provide explicit
__toString if you're printing or concatenating your objects.


--
gosha bine

extended php parser ~ http://code.google.com/p/pihipi
blok ~ http://www.tagarga.com/blok

 

Navigation:

[Reply to this 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

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