My friend wants me to tweak his website. But I'm getting the errors
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\htdocs\toolmanager\toolmanager\index.php on line 7
Fatal error: Cannot re-assign auto-global variable _REQUEST in C:\xampp\htdocs\toolmanager\toolmanager\includes\classloader_platform.php on line 154
when I try to run the code on apache with PHP5. Here's the code:
require("includes/classloader_platform.php");
line 7->$classloader =& NEW classloader('0','30',$_GET,'1');
$classloader->initialize($classloader);
line 154-> function __construct($cache=false,$cache_lifecycle=false,$_REQUEST,$template_parser=false) {
ini_set("memory_limit","200M");
//globalize _REQUEST
$this->_REQUEST=$_REQUEST;
...
I think it's because he wrote it by PHP4 standards so would it be better to switch apache to PHP4 or are there some simple fixes for these errors?
Do not revert to PHP 4. It is old and unsupported.
For "Deprecated: Assigning the return value of new by reference", just remove the &. It's redundant.
$classloader = NEW classloader(...);
For "Fatal error: Cannot re-assign auto-global variable", rename the function argument $_REQUEST to something else such as $REQUEST, then rename the subsequent occurrences of it within the function. You can't have a function argument with the same name as a superglobal.
function __construct($cache=false,$cache_lifecycle=false,$REQUEST,$template_parser=false) {
// ...
$this->_REQUEST=$REQUEST;
// ...
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.
I'm having an issue accessing the session variable from functions called from Thread objects using the pthreads library for PHP.
When the function is called from the main thread, no errors occur and everything runs fine.
When run from a Thread object however, I get the following errors:
> PHP Notice: Undefined variable: _SESSION
> PHP Notice: Undefined index: Properties Manager
> PHP Fatal error: Call to a member function getGroupValue() on a non-object
The line numbers specified by the errors all point to this code block:
function connect_mysql_db($database, $write = false) {
$properties = $_SESSION['Properties Manager'];
if(!isset($database) || strlen($database)==0){
throw new Exception("No database specified");
}
// Read appropriate host, port, dbname, user & pass for this database
$host = $properties->getGroupValue($database, DB_HOST);
$port = $properties->getGroupValue($database, DB_PORT);
$db_name = $properties->getGroupValue($database, DB_NAME);
...Removed unnecessary code...
}
A little searching says that I should be able to remedy this issue by putting session_start(); at the top of my file.
After doing this, the other errors are still printed in addition to:
> PHP Notice: A session had already been started - ignoring session_start()
So my main question: Is there something special that I need to do when using pthreads in order to access the super-global session? Or is there something completely different at play here that I am missing?
Edit:
Yes, I have tried global $_SESSION; as well.
After a bit more research, it seems that the session variable is not thread safe and in fact locks entirely until the session is closed. I had to remove references to the session and simply pass the needed information to the function or reinitialize it.
Luckily there isn't a performance downfall of the property manager being created.
I am using CodeIgniter and I have a problem
the code very simple just few row in the controller ,this is my controller
<?php
class Site extends Controller {
function index() {
echo 'i am here';
}
}
And this are the errors:
1- Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\ci\system\codeigniter\Common.php on line 130
2-Deprecated: Assigning the return value of new by reference is deprecated in C:\wamp\www\ci\system\codeigniter\Common.php on line 136
3-A PHP Error was encountered
Severity: 8192
Message: Assigning the return value of new by reference is deprecated
Filename: libraries/Loader.php
Line Number: 255
4-A PHP Error was encountered
Severity: 8192
Message: Assigning the return value of new by reference is deprecated
Filename: database/DB.php
Line Number: 133
I don't know where is the problem, certainly the code is correct but where is the problem. Any suggestions?
& is used in PHP to pass an object to a method / assign a new object to a variable by reference. It is deprecated in PHP 5 because PHP5 passes all objects by reference, but other vars default to by value.
To fix this error:
Update to the latest version of CodeIgniter, really!
Recently I faced the same prob, I was using codeigniter 1.7 and PHP 5.2.6 everything was working great, but after upgrading PHP to 5.3 the below error starts coming:-
Deprecated: Assigning the return value of new by reference is deprecated
The reason behind it is same as mentioned by #Amal , & is used in PHP to pass an object to a method / assign a new object to a variable by reference. It is deprecated in PHP 5 because PHP5 passes all objects by reference
For more info Refer to
Assigning the return value of new by reference is deprecated
So if you are creating your code from scratch, then better to use all the latest things, use codeigniter 2.1.4
But if you have your codebase in some old codeigniter version, then better to degrade your PHP (which is not recommended) till the time you move on to newer version.
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..