Forum

Meaning of "// FOR ...
 
Notifications
Retirer tout

Meaning of "// FOR PHP 7.1 COMPATIBILITY " in model/persistence/SqlElement.php

6 Posts
2 Utilisateurs
0 Reactions
3,756 Vu
(@glaurung4567)
Posts: 9
Active Member
Début du sujet
 
[#5249]

Hi,
I'm coding new functionnalities on Projeqtor as part of my traineeship. I created a new class with an attribute with a decimal type. I wish to keep the attribute to NULL when getting the objects from the db with getSqlElementsFromCriteria(...), but the function set my attribute from NULL to 0 on the line 2362.

I do not understand the condition nor the comment, could you explain it to me ? Here is the condition:

Thank you


 
Posté : 27 Juin PM 20:066
(@babynus)
Posts: 14952
Membre Admin
 

It wont be possible now to keep numeric value to zero.

It is due to major change on PHP 7.1.
Before PHP 7.1 : $a=1; $b=null; $c=$a+$b; // leads to $c=1
After PHP 7.1 : $a=1; $b=null; $c=$a+$b; // leads to error

So we had to manage numeric values to never be null, and replace them with 0 when read from db or from input.
(we could not get through the whole code to parse every sting used in arythmetic operation)
But I agree that it may be disapointing as Null value (no data entered) is not exactly the same as zero value (a zéro is amnually entered)


 
Posté : 29 Juin AM 11:066
(@glaurung4567)
Posts: 9
Active Member
Début du sujet
 

Well, i tested this case on a php sandbox and it didn't seem to present any problem.
Here the link: http://sandbox.onlinephpfunctions.com/code/a592b3405e7b77ce3a31c2206f6dec8b902a8a40

Sadly i don't have a server with PHP 7.1 (i work with wamp) so i can't test it on Projeqtor.


 
Posté : 29 Juin AM 11:066
(@babynus)
Posts: 14952
Membre Admin
 

Sadly i don't have a server with PHP 7.1 (i work with wamp) so i can't test it on Projeqtor.

You can easily have several versions of PHP on Wamp : http://wampserver.aviatechno.net/
(I have 5 on my dev one)
Try with ProjeQtOr V6.3.7 : you'll have the issues


 
Posté : 29 Juin PM 12:066
(@glaurung4567)
Posts: 9
Active Member
Début du sujet
 

Well, i dug deeper into the problem and reproduced the error on PHP 7.1 (I commented the lines to set the attribute to 0 when it's null in SqlElement.php).

But the cause isn't exactly the one you mentionned. It's the addition of a string of a float and an empty string which cause the warning ( http://sandbox.onlinephpfunctions.com/code/47caa167856dcacea3b3ff53533bc050b57059bc). Here the test I made on Projeqtor :

A possible solution might be to replace the first test of the condition ("if ($this->{$col_name}===null...") by " if ($this->{$col_name}===''"...".


 
Posté : 29 Juin PM 19:066
(@babynus)
Posts: 14952
Membre Admin
 

We'll have a try on V7.2 (under development)
But I'm afraid issues will occur.

if ($this->{$col_name}==='' 
and ( ( $dbType=='numeric') or ( $dbType=='decimal') )

cannot be true (db cannot store empty string in a numeric column)


 
Posté : 3 Juil PM 18:077
Share:
Retour en haut