Jump to content

Recommended Posts

Hello everyone!

 

First post here and its a question, bommer.

Well I need to have a system do a remote insert on a database, every X action the system would do this insert. Since the implementation could change we decided to host the actual function that does the insert in a remote server, and the client system would fetch this function and use it.

 

My approach was to fetch the code into a variable, create the function there with create_function and then just use it, it does work except for the parameters passed to the new function are not being taken into account by the code in the function.

So, there are inserts in the database, but with empty values.

 

Here is how I am building the function in the client system:


// remPath is defined elsewhere
$remFile = $this->readRemoteFile($remPath);
// now $remFile has the code in the form of not-a-function but using variables

// now I create the function
$doRemLog = create_function('$thisIp, $license, $currUrl, $comment, $isAttempt',$remFile);
// as you can see there are several variables, that are used in the code for the function in $remFile
// this is probably where I am wrong

// then I know the code is being executed properly because in the code for the function
// there is a check for the parameters to see if they are empty, this check is working
// on this line (me trying to call the function)
$doRemLog($thisIp,$license,$currUrl,$comment,"1");


 

Could any of you wise guys help me debug this?

in short, the function is being created and it works, the parameters used in the function are always being used as empty.

I did check, and they are not empty.

 

Thank you!

What do you get when you run this:

$remFile = <<<EOF
echo '<pre>' .  print_r(func_get_args(), 1) . '</pre>';
EOF;

$doRemLog = create_function('$thisIp, $license, $currUrl, $comment, $isAttempt', $remFile);

$doRemLog($thisIp, $license, $currUrl, $comment, 1);

You should get an array printed out showing you what each parameter is set to. What result do you get

 

Hello WildTeen,

 

I copy pasted it and im getting an error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

 

looked for it and found nothing funky... left some extra spaces for the heredoc but wasnt it...

I don't think its my code snippet causing that error. For me it is error free. I'm not sure. Its works fine for me with some dummy data:

<?php

$thisIp = '127.0.0.1';
$license = 'bla';
$currUrl = 'Unkown';
$comment = 'ohhh!';

$remFile = <<<EOF
echo '<pre>' .  print_r(func_get_args(), 1) . '</pre>';
EOF;


$doRemLog = create_function('$thisIp, $license, $currUrl, $comment, $isAttempt', $remFile);


$doRemLog($thisIp, $license, $currUrl, $comment, 1);

?>

 

I get this result:

Array

(

    [0] => 127.0.0.1

    [1] => bla

    [2] => Unkown

    [3] => ohhh!

    [4] => 1

)

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.