CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 7 of 7
  1. #1
    Join Date
    Jan 2006
    Posts
    352

    [RESOLVED] PHP: Mimic built in function

    I must admit, that I am fascinated with method bind result

    $stmt->bind_result($col1, $col2);

    Because it can take non fixed number of arguments.
    In this case those are variables, which were NOT created / declared anywhere before!

    They also are referenced and get value later.

    I've tried to recreate that behaviour, but failed!

    PHP Code:
    function xperiment()
    {
       
       
    $numargs func_num_args();
        
       
    $arg_list func_get_args();
       
       for (
    $i 0$i $numargs$i++)
       {
           
    $arg_list[$i] &= rand(1100);
           
           echo 
    "Argument $i is: " $arg_list[$i] . NL;
       }
       
    }


    xperiment($one$two$three);



    echo 
    "$one$two$three"
    I can't even make it free of:
    Code:
    Notice:  Undefined variable:....
    And failed to reference it!


    I think it would really be a fun, to "crack it"
    Ipsens

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP: Mimic built in function

    That's because you aren't declaring what $one, $two, and $three are when you pass them as variables to the function xperiment.

    PHP Code:
    $one 'One';
    $two 'Two';
    $three 'Three';

    xperiment($one$two$three);

    //or
    xperiment('One''Two''Three'); 
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jan 2006
    Posts
    352

    Re: PHP: Mimic built in function

    Quote Originally Posted by PeejAvery View Post
    That's because you aren't declaring what $one, $two, and $three are when you pass them as variables to the function xperiment.....
    That is a point!

    NOT to declare variables anywhere!
    They FIRSTLY appear, like arguments supplied to that function:
    PHP Code:
    xperiment($one$two$three); 
    JUST like in a case of stmt_bind_result.
    Ipsens

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP: Mimic built in function

    Okay, I misread your first post.

    The reason this happens is because of the mysqli class itself. I doubt you can recreate because of the need for variable declaration within PHP. If you were using C to write your own PHP class, then imitating it would be easy.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jan 2006
    Posts
    352

    Re: PHP: Mimic built in function

    Actualy it is $stmt class in play, created by MySQLi class.

    So..., that is final?
    It can't be done!?

    I wanted to create such function which would receive as many variables as I wanted.
    That function would declare them and populate them with some values, by reference without returning them.

    So I could just continue to use those vars normally inside PHP script.

    Well, I guess it can't be done as PHP is created in C language.
    Ipsens

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: PHP: Mimic built in function

    You can create a function that will receive an infinite number of variables. But, the data passed as the parameters must be defined.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  7. #7
    Join Date
    Jan 2006
    Posts
    352

    Re: PHP: Mimic built in function

    Quote Originally Posted by PeejAvery View Post
    You can create a function that will receive an infinite number of variables. But, the data passed as the parameters must be defined.
    Yes, I know that.
    But, after that comes PHP's limitation.
    Ipsens

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured