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.
Related
I'm using PHP class from https://github.com/constantcontact/Constant-Contact-PHP-Sample-Contact-Forms to add new contacts to Constant Contact list, but recently I have got PHP error messages:
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 1
Filename: cc_class.php
Line Number: 248
A PHP Error was encountered
Severity: Notice
Message: Undefined offset: 1
Filename: cc_class.php
Line Number: 252
where those lines look like:
(248)
$xml = simplexml_load_string($return);
(252)
}
and full related function to those two lines:
public function subscriberExists($email = '') {
$call = $this->apiPath.'/contacts?email='.$email;
$return = $this->doServerCall($call);
$xml = simplexml_load_string($return);
$id = $xml->entry->id;
if($id){ return $id; }
else { return false; }
}
but it passes data to Constan Contact anyway.
Any clue what is going on there with those error messages?
Thanks
From the class GitHub
This is just a PHP notice, not a failure, when trying to access an
index of an array that hasn't been defined yet. The codebase in this
app is fairly old, and hasn't been brought up to date as PHP is
upgraded.
We would recommend instead of using this repo, utilizing the newer PHP
SDK which is object-oriented, available via composer, and kept up to
date. You can definitely mute these notifications in your environment,
but this repo is deprecated, so this issue won't be addressed in the
project.
I hope you are all fine.
Recently, my host has upgraded the PHP version to PHP 5.4. I cannot use my web application "myclientbase" any longer. Some features like auto suggestion are no longer available. Is there any way to keep the old version of PHP 5.3? I didn't face any issues while using this version.
Please check the below errors;
A PHP Error was encountered
Severity: Warning
Message: Creating default object from empty value
Filename: models/mdl_mcb_data.php
Line Number: 88
A PHP Error was encountered
Severity: Warning
Message: Creating default object from empty value
Filename: models/mdl_mcb_userdata.php
Line Number: 76
Thank you very much for your help.
1) Open
/application/modules_core/mcb_data/models/mdl_mcb_data.php
/application/modules_core/mcb_data/models/mdl_mcb_userdata.php
/application/modules_core/mcb_data/models/mdl_mcb_client_data.php
2) after public $settings line 5 insert
public function __construct() {
if(empty($this->settings))$this->settings= new stdClass();
}
1) Open /application/modules_core/mcb_data/models/mdl_mcb_data.php
2) Go to line 77
3) Change
foreach ($mcb_data as $data) {
$this->settings->{$data->mcb_key} = $data->mcb_value;
}
to
$this->settings=new stdClass();
foreach ($mcb_data as $data) {
$this->settings->{$data->mcb_key} = $data->mcb_value;
}
go to root folder
open index.php
change error_reporting(E_ALL); at line 34 to error_reporting(0);
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..
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;
// ...
I have put the files I downloaded from http://www.openwall.com/phpass/ to application/libraries
In my controller, I am using this code -
$params = array(
'phpass_hash_strength' => 8,
'phpass_hash_portable' => FALSE
);
$this->load->library('PasswordHash', $params);
$password = $this->passwordhash->HashPassword($pwd);
I am getting these errors -
A PHP Error was encountered
Severity: Notice
Message: Uninitialized string offset: 3
Filename: libraries/PasswordHash.php
Line Number: 116
A PHP Error was encountered
Severity: Warning
Message: strpos() [function.strpos]: Empty delimiter
Filename: libraries/PasswordHash.php
Line Number: 116
Update
Removed PasswordHash.php, using SimpleLoginSecure now.
I had the same issue whilst integrating PasswordHash into Symfony2.
To solve it, I renamed the PasswordHash method to __construct.
In theory, PHP 5+ should look for a method with the same name as the class if it can't find a constructor (http://php.net/manual/en/language.oop5.decon.php). My guess is that the class name resolves differently once a namespace is added (a requirement for my integration), but I've not investigated at all.
I think your problem is you are trying to use a generic PHP object as a CodeIgniter library. You can't just do that. You'll need to modify the original code to work, or download one of the contributed libraries already designed for CodeIgniter.
CodeIgniter libraries have some restrictions (such as how they are instantiated), so just dropping any file into the libraries folder won't work.