1

Hi friends i get some array value from an other page and i should put this value in my 'wp-posts' table. For this i have created a function, which receive an array value and db connection value. Below you can see how i sent a value to this function.

foreach ($avaible as $listingx) {
    AddPost(&$mysqli, $listingx);
    }

And here belowe i try first to write in my log file this values.

function AddPost(&$mysqli, $listing){   
    foreach ($listing as $key => $value) {
        mylog(" key ::".print_r($key, TRUE));
        mylog(" value ::".print_r($value, TRUE));
    }
}

Write in the log file had worked in the same file to other function. But in AddPost function is this not working .And when it come to "AddPost()" after that it's not working. Please can some one tell me why this function is not working.

1 Answer 1

1

You're using references wrong: the reference sign should be used on the function definition, not on the function call. So change this :

AddPost(&$mysqli, $listingx);

To this :

AddPost($mysqli, $listingx);

From PHP Doc:

There is no reference sign on a function call - only on function definitions. Function definitions alone are enough to correctly pass the argument by reference. As of PHP 5.3.0, you will get a warning saying that "call-time pass-by-reference" is deprecated when you use & in foo(&$a);. And as of PHP 5.4.0, call-time pass-by-reference was removed, so using it will raise a fatal error.

If you had enabled WP_Debug you should have seen an error about this.

Sign up to request clarification or add additional context in comments.

3 Comments

Ok but even when i don't used this"$mysqli" variable, it's not working.
Could you be more specific about what is not working? Does the function is called at all? What's the code of the mylog function? Please provide some debug informations.
Ah sorry it's my fault i did't close the function "}". Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.