Call function from converted Array ?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • smartic
    New Member
    • May 2007
    • 150

    Call function from converted Array ?

    Code:
    <?php
    $ar = (object) array('a'=>function(){
    	echo 'TEST';
    });
    $ar->a();
    ?>
    I get this error Call to undefined method
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    var_dump($ar)
    that should give you an idea, what your object looks like.

    Comment

    • smartic
      New Member
      • May 2007
      • 150

      #3
      can you tell me how can i call the function ?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        what’s the output from var_dump($ar) ?

        Comment

        • smartic
          New Member
          • May 2007
          • 150

          #5
          object(stdClass )[2]
          public 'a' =>
          object(Closure)[1]

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #6
            try {$ar->a}();. the point is that "a" is not a Method, it’s a Property (and unlike to JavaScript, that’s not the same)

            Comment

            • smartic
              New Member
              • May 2007
              • 150

              #7
              Parse error: syntax error, unexpected '}' in

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #8
                then you did not copy correctly

                Comment

                • smartic
                  New Member
                  • May 2007
                  • 150

                  #9
                  I did copy it correctly maybe my version of PHP 5.3.10 ?



                  Comment

                  Working...