I'm trying to deploy Wordpress on Dotcloud using this repo but there is an error that appears in the logs:
18:59:19: [www.0] Running postinstall script...
18:59:21: [www.0] PHP Fatal error: Call-time pass-by-reference has been removed in /home/dotcloud/rsync-1353715101184/dotcloud-scripts/feed-wp-config.php on line 86
Looking at line 86 in feed-wp-config.php, it reads:
$content = preg_replace('/(define\(\'' . $property . '\', \')(.*)(\'\);)/', '${1}' . $value . '${3}', $content, -1, &$count);
When I go to the Wordpress start page it says, "There doesn't seem to be a wp-config.php file. I need this before we can get started."
I've cross-posted this to the repo's Github issue tracker, but as there hasn't yet been a response I'm posting it here as well in hopes that someone knows the answer.
Replace &$count with just $count. & meant you want variable to be passed by reference, not value:
Documentation says
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);.
So if you want to pass variable by reference to the function, you should use & in function declaration:
This now should be done that way:
// right
function foo(&$var) {
...
}
foo($foo);
but not that way (as you get this warning):
function foo($var) {
...
}
foo(&$foo); // <--- wrong
Remove the & sign from the &$count at the end of the line.
Please bear in mind, that this is a core hack in wordpress, and it will be lost on an update..
Related
I am using WooCommerce on Wordpress 4.7.1. Previously, I was running 4.7.0. When Wordpress automatically upgraded to 4.7.1, I suddenly began seeing checkouts fail to redirect to the "Thank you" page, and the UI showed that a fatal error had occurred.
Turning on debugging revealed the following error:
PHP Fatal error: Cannot redeclare get_cc() (previously declared in .../templates/emails/email-addresses.php:36) in .../templates/emails/email-addresses.php on line 36
I also confirmed that this file is never directly called with require, require_once, include, or include_once. It is, however, called with wc_get_template().
A quick search brought me to this similar question. So I added the following to email-addresses.php:
if (!function_exists('get_cc')) {
function get_cc( $code ) {
... function body
}
}
After making this change, I now receive the following error in the debug log:
PHP Fatal error: Call to undefined function get_cc() in .../templates/emails/email-addresses.php on line 32
This means that, for whatever reason, PHP believes that the function get_cc already exists, but at the same time it is undefined.
I was not the original developer. I took over the project from a contractor who is not available. It does seem clear that this file is heavily modified from the original. I am certain that the value returned by the function must be kept, so I cannot just comment out the call.
Given the information above, what options do I have to either workaround or fix this issue?
It turns out that, unlike a standard function definition in PHP, function definitions wrapped in if (!function_exists('function_name')) { ... } block must precede any call to that function.
In this case, the function definition (line 36) followed the call (line 32). This caused the function to appear to PHP as undefined:
// Not working!
$value = get_cc($code);
if (!function_exists('get_cc')) {
function get_cc( $code ) {
...
}
}
Switching the order so that the function definition came first fixed the issue:
// Working!
if (!function_exists('get_cc')) {
function get_cc( $code ) {
...
}
}
$value = get_cc($code);
As of right now, PHP's documentation does not mention this issue.
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.
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.
Why is this line of code:
$this->plugins_dir[0] = SMARTY_DIR . 'plugins';
causing this error?
ERRNO: 8
TEXT: Indirect modification of overloaded property Page::$plugins_dir has no effect
By the way, the line of code is inside the constructor of a class named 'Page'.
I am working with PHP and PostgreSQL, but am not too experienced. I am stuck
with this problem for few hours now, can't find the reason.
What PHP is trying to tell you is that the property ->plugins_dir doesn't really exist, but a magic __get() function has been written that will return a value if you read from it. Assigning a variable directly to it might also work (if there is a corresponding __set()) but you cannot modify it, since it is actually a function return value. You are effectively trying to say $this->__get('plugins_dir')[0] = 'foo', which doesn't mean anything.
However, looking at the relevant Smarty documentation, we can see what the correct solution is:
Note: As of Smarty 3.1 the attribute $plugins_dir is no longer accessible directly. Use getPluginsDir(), setPluginsDir() and addPluginsDir() instead.
So your code should actually use the pattern of one of the examples on the doc page for addPluginsDir(), such as:
$this->setPluginsDir( SMARTY_DIR . 'plugins' )
->addPluginsDir( '/some/other/source/of/plugins' );
I think this is the right way
$this->plugins_dir = SMARTY_DIR . 'plugins';
function getContactActiveEmails($eid)
{
global $db;
if ($eid) {
$sql = "SELECT email FROM activeEmails WHERE id = $eid";
return $db->GetCol($sql);
}
}
I get the error "Cannot redeclare function getContactActiveEmails"
The line number it gives is the last line of the function - the }
All files are being called with require_once. This is the only place in the entire codebase where getContactActiveEmails is being defined. Why is this?
It is very clear from the error your function is defined twice hence you are getting the error.
I would recommend that check if the function is already defined before declaring it.
if (!function_exists('getContactActiveEmails'))
{
function getContactActiveEmails($eid)
{
global $db;
if ($eid) {
$sql = "SELECT email FROM activeEmails WHERE id = $eid";
return $db->GetCol($sql);
}
}
}
solution by #Shakti Singh will work, but keep in mind that you are loosing control of your code - you do not know where is this function declared and what does it return, so I suggest looking for it
Try case insensitive search, many text editors and IDEs search case-sensitive by default and your function can be as well declared as getcontactactiveemails somewhere.
If still no luck make php say something about this function, using Reflection extension
Example usage of reflection:
if(function_exists('getContactActiveEmails')){
$myfunc = new ReflectionFunction('getContactActiveEmails');
echo 'Function is declared in '.$myfunc->getFileName().
' starting from line '.$myfunc->getStartLine().
' to '.$myfunc->getEndLine();
die;
}
More about Reflection
I'm getting the same issue. I have a standard file called adhoc.inc.php which is imported into almost every php file on my site. With no changes being made to any code over night i started seeing the error
[13-Jul-2013 21:19:22 Australia/Sydney] PHP Fatal error: Cannot redeclare checkloggedin() in /Applications/MAMP/htdocs/mycobber/util/adhoc.inc.php on line 4
Initially I only got it in a few files so i just commented out this import and it worked. Suddenly, again no changes, I was getting this in every file i loaded. I figured this wasn't me so I restarted my MAMP servers (apache and mysql) and then it went away.
Has anyone seen this before?
This error occurs if you have your function defined in a loop, since you're trying to define it in each iteration.
I am new to using simpletest: http://www.simpletest.org/ for PHP and am using PHP 5.2* on my server, when I try to set up an initial test script based on their demo, I get a page full of errors like the one below... I am not sure if this is something to do with simpletest not being compatible with PHP 5.* or what the issue is, any insight is appreciated.. it seems that I can still use the library as it returns what seems to be appropriate below the errors, but I would like to understand this so I can fix it.. thanks
Here is an example of the php code I am using to call a simpletest function
<?php
require_once('C:/wamp/www/external/simpletest/simpletest/autorun.php');
class TestOfLogging extends UnitTestCase {
function testFirstLogMessagesCreatesFileIfNonexistent() {
#unlink(dirname(__FILE__) . '/../temp/test.log');
$log = new Log(dirname(__FILE__) . '/../temp/test.log');
$log->message('Should write this to a file');
$this->assertTrue(file_exists(dirname(__FILE__) . '/../temp/test.log'));
}
}
?>
And the error I get:
Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\external\simpletest\simpletest\unit_tester.php on line 74
Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\external\simpletest\simpletest\unit_tester.php on line 89
"Deprecated" means that something old-fashion, that possibly won't be supported by future versions of php is done. It should not be harmful, but should be taken care of by simpletest developers. Did you download the latest version of simpletest?
If you want to understand, take a look at unit_tester.php on lines 74 and 89.
Rather than switching all errors off, just switch off deprecation warnings. The alternative is to do a find-and-replace on all the simpletest files: find "&new" and replace with "new". new by reference (&new) was only deprecated in PHP5.3, so hopefully that'll be fixed in the next SimpleTest release.
Are you sure you're using 5.2, and not 5.3, when running the unit tests? I seem to remember seeing these errors with PEAR packages running under 5.3.
I also had this problem while going through the simpletest tutorial.
To make these messages go away, I changed the display_errors = On setting in my php.ini file to display_errors = Off.