Closed korenevskiy closed 3 years ago
The use of get_object_vars
was added there with PR #25761 and will be back-integrated with #33633 into staging/3.9.x.
@Hackwar Since the original PR #25761 was yours: Could you check this issue here and let us know your thoughts on it? Thanks in advance.
I don't think the PRs are related. For this requirement, @korenevskiy has can implement check()
method in the table class to check if certain fields has empty value and set default value for it in the way he wants. That's how we do in Joomla, see https://github.com/joomla/joomla-cms/blob/4.0-dev/libraries/src/Table/Content.php#L214 for example
The problem here is that look like he does not want to do that and want Joomla to do all magic things to set default values for these fields automatically. From what I can see, it is not possible, at least for our current code.
@joomdonation So we close it as expected behaviour?
At least this is not an issue. Move to discussion if needed but from what I see, this is something we won't support.
@joomdonation @richard67
Of course, this is solved with a crutch. But joomla is not only a CMS, it is also a framework. The Table, Factory, and Helpers classes are classes that make life easier. I have already solved my problem, I have set the default values to 0 and ". I suggest improving the FrameWork as a tool to make life easier. . PHP 8 introduces another level of typing in classes. What is the use of this innovation? If you then need to do unnecessary type checks.
We still have to support PHP versions lower than 8 with Joomla 4.
@richard67 The framework must bind itself even for typed data. But it should also be able to work as before in 7.4 without typing. This problem does not conflict with PHP 7.4 I didn't create this ISSUE because it's not solvable at all. But because the framework should be of high quality, making life easier.
I move this to discussions.
I created a class
Loading JSON.
$object = json_decode($json, true);
Save data.
But data with empty values is saved to the database.
I spent a lot of time looking for the problem. Even the site //php.net does not report PHP restrictions The
Table->bind()
method has exactly the same behavior.The fact is that the
Table->GetProperties()
method has the codeget_object_vars()
. But theget_object_vars()
function has limitations. For the function to work, it needs to get the property names with their own values. But there are no default values in the JTable Products class. TheTable->Bind()
method and theTable->Save()
method do not use the original property values at all, these methods only set new values with properties. This problem is a bug of PHP developers. After all, it is obvious that int fields by definition should have a default value of 0. Why do I need to set default property values if I'm going to explicitly override the properties (inTable->save()
andTable->bind()
)? I suggest using something else in theTable->GetProperties()
method instead ofget_object_vars()
. However, theTable-set()
method works in all cases, and theTable->save()
method should also work in all binding cases.