Functions and defaults

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Bob Stearns

    #1

    Functions and defaults

    Consider a function header:

    function init($name, $ttl, $need_bhid="N", $need_entity_id ="N")

    What values do the last two parameters have when it is called with the
    following arguments:

    init("name", "do name",,"Y");
  • Andy Hassall

    #2
    Re: Functions and defaults

    On Mon, 19 Jun 2006 17:50:52 -0400, Bob Stearns <rstearns1241@c harter.net>
    wrote:
    [color=blue]
    >Consider a function header:
    >
    >function init($name, $ttl, $need_bhid="N", $need_entity_id ="N")
    >
    >What values do the last two parameters have when it is called with the
    >following arguments:
    >
    >init("name", "do name",,"Y");[/color]

    That's a syntax error.
    --
    Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
    http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

    Comment

    • Bob Stearns

      #3
      Re: Functions and defaults

      Andy Hassall wrote:[color=blue]
      > On Mon, 19 Jun 2006 17:50:52 -0400, Bob Stearns <rstearns1241@c harter.net>
      > wrote:
      >
      >[color=green]
      >>Consider a function header:
      >>
      >>function init($name, $ttl, $need_bhid="N", $need_entity_id ="N")
      >>
      >>What values do the last two parameters have when it is called with the
      >>following arguments:
      >>
      >>init("name" , "do name",,"Y");[/color]
      >
      >
      > That's a syntax error.[/color]
      That is too bad. It really should be "N" and "Y" with PHP honoring the
      default values for all omitted arguments, not just trailing ones. Does
      PHP v 5.x do it better?

      Comment

      • Andy Hassall

        #4
        Re: Functions and defaults

        On Mon, 19 Jun 2006 19:16:06 -0400, Bob Stearns <rstearns1241@c harter.net>
        wrote:
        [color=blue]
        >Andy Hassall wrote:[color=green]
        >> On Mon, 19 Jun 2006 17:50:52 -0400, Bob Stearns <rstearns1241@c harter.net>
        >> wrote:
        >>[color=darkred]
        >>>Consider a function header:
        >>>
        >>>function init($name, $ttl, $need_bhid="N", $need_entity_id ="N")
        >>>
        >>>What values do the last two parameters have when it is called with the
        >>>following arguments:
        >>>
        >>>init("name ", "do name",,"Y");[/color]
        >>
        >> That's a syntax error.[/color]
        >
        >That is too bad. It really should be "N" and "Y" with PHP honoring the
        >default values for all omitted arguments, not just trailing ones. Does
        >PHP v 5.x do it better?[/color]

        No, C++-style skipping arguments in the middle of a list of arguments with
        defaults is not supported in any current version of PHP.

        (I don't know whether will be or not in PHP 6).
        --
        Andy Hassall :: andy@andyh.co.u k :: http://www.andyh.co.uk
        http://www.andyhsoftware.co.uk/space :: disk and FTP usage analysis tool

        Comment

        • Bob Stearns

          #5
          Re: Functions and defaults

          Andy Hassall wrote:[color=blue]
          > On Mon, 19 Jun 2006 19:16:06 -0400, Bob Stearns <rstearns1241@c harter.net>
          > wrote:
          >
          >[color=green]
          >>Andy Hassall wrote:
          >>[color=darkred]
          >>>On Mon, 19 Jun 2006 17:50:52 -0400, Bob Stearns <rstearns1241@c harter.net>
          >>>wrote:
          >>>
          >>>
          >>>>Consider a function header:
          >>>>
          >>>>function init($name, $ttl, $need_bhid="N", $need_entity_id ="N")
          >>>>
          >>>>What values do the last two parameters have when it is called with the
          >>>>following arguments:
          >>>>
          >>>>init("name" , "do name",,"Y");
          >>>
          >>> That's a syntax error.[/color]
          >>
          >>That is too bad. It really should be "N" and "Y" with PHP honoring the
          >>default values for all omitted arguments, not just trailing ones. Does
          >>PHP v 5.x do it better?[/color]
          >
          >
          > No, C++-style skipping arguments in the middle of a list of arguments with
          > defaults is not supported in any current version of PHP.
          >
          > (I don't know whether will be or not in PHP 6).[/color]
          Put me down for a positive vote if one is being taken :-)

          Comment

          Working...