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
[Back to original message]
|