You are here: Re: Passing null for a class-typed argument renders catchable error ?!? « PHP Programming Language « IT news, forums, messages
Re: Passing null for a class-typed argument renders catchable error ?!?

Posted by seaside on 01/13/08 03:38

On 13 Jan., 04:32, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> seaside wrote:
> > On 13 Jan., 04:00, "Rik Wasmus" <luiheidsgoe...@hotmail.com> wrote:
> >> On Sun, 13 Jan 2008 03:50:33 +0100, seaside <seaside...@mac.com> wrote:
> >>> I have a method
> >>>   function appendChildNode( AST $aNewChild ) {
> >>>   ...
> >>>   }
> >>> <<<
> >>> where AST is a class. If I pass null, PHP renders this message:
> >>> Catchable fatal error: Argument 1 passed to AST::appendChildNode()
> >>> must be an instance of AST, null given, called in /Applications/MAMP/
> >>> htdocs/compile/includes/CParser.inc.php(517) : eval()'d code on line 1
> >>> and defined in /Applications/MAMP/htdocs/compile/includes/AST.inc.php
> >>> on line 43
> >>> <<<
> >>> Any ideas, why I can't pass a null value?
> >> For some reason:
>
> >> function appendChildNode( AST $aNewChild = NULL ) {
>
> >> }
>
> > But now, I can call it 'legally' with no parameters, which I don't
> > want.
> > At least any reader would think, 'OK, passing no value is OK'.
>
> > Do we have other options?
>
> > Additionally: I'll go into details of the code soon, but does the
> > default value make to
> > exception disappear, since I passed no value at all to appendChildNode?
>
> As Rik pointed out, type hinting is a somewhat inconsistent operation in
> PHP.  But this a new area for PHP, and I'm not sure it's been entirely
> thought out yet (as seems to be with a lot of things in PHP).

Thx, Jerry! In fact, the app failed to pass a value as an argument to
appendChildNode().

I'm building a parser generator and fetched a returned value from a
non-terminal symbol
from the wrong (let's say) stack frame.

Fixed it, removed the ' = NULL' - and things work fine.

Thx again for all quick answers!

 

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

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