error with &$variable

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

    error with &$variable



    Parse error: syntax error, unexpected '=', expecting ')'

    on function so

    function pippo($var1, &$var2 = null, $var3 = null) { ....}

    but if remove &
    I not have the erros;

    I must change sometime in php.ini or can resolve how?
    I use php4.x
  • =?iso-8859-1?Q?=C1lvaro?= G. Vicario

    #2
    Re: error with &$variab le

    *** artev escribió/wrote (Tue, 12 Aug 2008 23:30:42 +0200):
    function pippo($var1, &$var2 = null, $var3 = null) { ....}
    >
    but if remove &
    I not have the erros;
    >
    I must change sometime in php.ini or can resolve how?
    I use php4.x
    According to the manual, you must upgrade to PHP 5 or rewrite your
    function. PHP 4 doesn't allow the combination of passing by reference and
    default values:




    --
    -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
    -- Mi sitio sobre programación web: http://bits.demogracia.com
    -- Mi web de humor en cubitos: http://www.demogracia.com
    --

    Comment

    • artev

      #3
      Re: error with &$variab le

      According to the manual, you must upgrade to PHP 5 or rewrite your
      function. PHP 4 doesn't allow the combination of passing by reference and
      default values:
      >
      http://es2.php.net/manual/en/functions.arguments.php
      ok so this work only in php5
      function pippo($var1, &$var2 = null, $var3 = null) { ....}

      but if I write so:
      function pippo($var1, &$var2, $var3 = null)
      {
      if(!&$var2) {&$var2 = null}
      .....
      }

      I can resolve?

      Comment

      • Jerry Stuckle

        #4
        Re: error with &$variab le

        artev wrote:
        >According to the manual, you must upgrade to PHP 5 or rewrite your
        >function. PHP 4 doesn't allow the combination of passing by reference and
        >default values:
        >>
        >http://es2.php.net/manual/en/functions.arguments.php
        >
        ok so this work only in php5
        function pippo($var1, &$var2 = null, $var3 = null) { ....}
        >
        but if I write so:
        function pippo($var1, &$var2, $var3 = null)
        {
        if(!&$var2) {&$var2 = null}
        ....
        }
        >
        I can resolve?
        >
        if (!$var2) {$var2 = null;}

        --
        =============== ===
        Remove the "x" from my email address
        Jerry Stuckle
        JDS Computer Training Corp.
        jstucklex@attgl obal.net
        =============== ===

        Comment

        • =?iso-8859-1?Q?=C1lvaro?= G. Vicario

          #5
          Re: error with &$variab le

          *** artev escribió/wrote (Wed, 13 Aug 2008 17:18:43 +0200):
          ok so this work only in php5
          function pippo($var1, &$var2 = null, $var3 = null) { ....}
          >
          but if I write so:
          function pippo($var1, &$var2, $var3 = null)
          {
          if(!&$var2) {&$var2 = null}
          ....
          }
          It's not exactly the same. This way you must call pippo() with at least
          $var1 and $var2, so $var2 is no longer optional.

          I can think of a couple of tricks but it looks like that the best solution
          would be a small redesign.



          --
          -- http://alvaro.es - Álvaro G. Vicario - Burgos, Spain
          -- Mi sitio sobre programación web: http://bits.demogracia.com
          -- Mi web de humor en cubitos: http://www.demogracia.com
          --

          Comment

          • artev

            #6
            Re: error with &$variab le

            Il Wed, 13 Aug 2008 18:14:32 +0200, Álvaro G. Vicario ha scritto:
            *** artev escribió/wrote (Wed, 13 Aug 2008 17:18:43 +0200):
            >ok so this work only in php5
            >function pippo($var1, &$var2 = null, $var3 = null) { ....}
            >>
            >but if I write so:
            >function pippo($var1, &$var2, $var3 = null)
            >{
            >if(!&$var2) {&$var2 = null}
            >....
            >}
            >
            It's not exactly the same. This way you must call pippo() with at least
            $var1 and $var2, so $var2 is no longer optional.

            function pippo($var1, &$var2 = null, $var3 = null) { ....}
            but also so $var2 is no longer optional ?

            Comment

            • Michael Fesser

              #7
              Re: error with &$variab le

              ..oO(artev)
              >According to the manual, you must upgrade to PHP 5 or rewrite your
              >function. PHP 4 doesn't allow the combination of passing by reference and
              >default values:
              >>
              >http://es2.php.net/manual/en/functions.arguments.php
              >
              >ok so this work only in php5
              >function pippo($var1, &$var2 = null, $var3 = null) { ....}
              >
              >but if I write so:
              >function pippo($var1, &$var2, $var3 = null)
              >{
              >if(!&$var2) {&$var2 = null}
              >....
              >}
              >
              >I can resolve?
              Upgrade to PHP 5.

              Micha

              Comment

              Working...