-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Deprecated (8192): Automatic conversion of false to array is deprecated [CORE\Cake\Model\Model.php, line 1232] #72
Comments
Hi again @pbriongos! I'm having trouble duplicating this error. I can see how it could be triggered if Are you somehow altering your model object's @kamilwylegala What do you think? It would be easy to implement a fix similar to the I18n false-to-array fix that was just merged, but I'm not sure this is so universal. |
@pbarabe I agree. @pbriongos It's interesting what's in:
Or how your model is defined. |
Hi,
Maybe the datasource is doing incorrect things whit $this->data. Anyways, the deprecated notice can be avoided writing this in Model.php: |
Hi @pbriongos! Your code is a bit out of the ordinary for the way model data is usually saved/updated in CakePHP 2, and I think that's why you're encountering this error. The conventional approach, per CakePHP documentation, would be more like this: <?php
App::uses('AppController', 'Controller');
class EmailsController extends AppController
{
// Explicit declaration of Model class(es) used by this Controller
public $uses = ['Email'];
// ... other class properties and methods
public function edit($id = null) {
if (!$this->Email->exists($id)) {
throw new NotFoundException(__('Invalid email'));
}
// If HTTP request is POST or PUT, try to update the requested record
if ($this->request->is(array('post', 'put'))) {
// Standard usage of Model CRUD methods, ie. $this->ModelName->save($data);
if ($this->Email->save($this->request->data)) {
$this->Flash->success(__('The email has been saved.'));
return $this->redirect(array('action' => 'index'));
} else {
$this->Flash->error(__('The email could not be saved. Please, try again.'));
}
// If HTTP request is not POST or PUT, find the requested record
} else {
$options = array('conditions' => array('Email.' . $this->Email->primaryKey => $id));
$this->request->data = $this->Email->find('first', $options);
}
}
// ... more class methods
} Also, I hope you don't mind me saying, but if this is a new project you're working on, I'd strongly recommend considering starting with a more up-to-date version of CakePHP (ie. 4.x or 5.x). cakephp2-php8 is really intended to provide backward compatibility for established projects built on CakePHP 2.x that cannot easily be upgraded. I hope that's all helpful! |
@pbarabe I'm developing with CAKE from nearly 15 years ago, I'm working in a 5000 employees enterprise and the project is in CAKE 2 (started in 2015), we have nearly 500 controllers and a lot of improvements to CAKE, so I have "a bit" experience with CAKE. So I don't want to upgrade to 3.x or 4.x because it's impossible with this huge project, it's very established and works very well. So I need to be compatible with last versions of PHP, so I need to be updated with this topic. I repaired this DEPRECATED notice as I said with just a line, so if you want to take it ok. I need the mongo datasource, so this is what it is. |
Hello, Deprecated (8192): Automatic conversion of false to array is deprecated [CORE\Cake\Model\Model.php, line 1232] Upon investigation, I found that this warning is triggered due to the automatic conversion of false to an array. To address this, I suggest modifying the code in Vendor/cakephp/cakephp/lib/Cake/Model/Model.php at line 1982. Currently, the code is: $this->data = false; I propose changing it to: $this->data = array(); This change will prevent the deprecated warning by directly assigning an empty array instead of false. Thank you for your efforts in maintaining CakePHP compatibility with PHP 8. I hope this suggestion is helpful. Best regards |
Hi @pbriongos Apologies, I'd gotten the impression this was all new to you and was intending to to helpful. I see I was mistaken. All good, I hope. Both your suggested change and that of @aokazu could be helpful. I'll defer to @kamilwylegala since he is the maintainer. |
I'm glad I could help. |
On updating row in a model:
Deprecated (8192): Automatic conversion of false to array is deprecated [CORE\Cake\Model\Model.php, line 1232]
Trace:
The text was updated successfully, but these errors were encountered: