Replies: 6 comments 39 replies
-
I took the courage and copied the function description from discussion. To close the previous discussion. function isTrue($value){
if($value === false || $value === null || $value == 0 || $value == '' || $value == 'false' || $value == '0'
|| $value == 'disabled' || $value == 'off' || $value == 'no' || $value == 'none')
return false;
return true;
} This is an approximate writing of the function. But the need for such a feature in Joomla is obvious. @nibra I don't understand the purpose of casting types to other types. In the past, I have already written a type conversion function for the properties of objects and database fields. This table class is under development. This class is fully operational, and supports full backward compatibility. But testing this class requires a large number of applicants. So I decided to change this @nibra Did you mean to create a type conversion package, at the same time to support type conversion for the database ? |
Beta Was this translation helpful? Give feedback.
-
For the time being, this discussion should be open-ended. To solve the Boolean problem, a class is needed that converts string representations into PHP types. However, it may make sense to offer additional conversion classes for other targets, e.g. SQL, perhaps in a later step. |
Beta Was this translation helpful? Give feedback.
-
I fully support you that SQL type conversion is not applicable in this topic, since it does not make sense without a typed table. We'll put it off for later. I propose to divide the current task into 2 independent processes. Note that it is the independent processes. Later, we may move something and rename it. But now we can make a preliminary (draft) PR, 2-3 functions. This will already be the beginning for discussing the logic of the file. But also at the same time, beginners who do not understand what is at stake can familiarize themselves with the existing library and make their suggestions. The method written above Can we use |
Beta Was this translation helpful? Give feedback.
-
It internally knows the valid true/false pairs and decides which one to choose depending on the value provided to the constructor. $var = new Boolean('show');
echo $var; // Result: 'show'
$var->negate();
echo $var; // Result: 'hide' $var = new Boolean('on');
echo $var; // Result: 'on'
$var->negate();
echo $var; // Result: 'off' $var = new Boolean('yes');
echo $var; // Result: 'yes'
$var->negate();
echo $var; // Result: 'no' and so on. |
Beta Was this translation helpful? Give feedback.
-
$var = $field['show_title'];
echo $var; // Result: 'yes'
boolean_negate($var);
echo $var; // Result: 'no' or $var = 'show';
echo $var; // Result: 'yes'
boolean_negate($var);
echo $var; // Result: 'no' / * *
* @param mixed $var
* @return string
*/
function boolean_negate($var) : string{
} an easy-to-understand script, easy to read. // Static methods
echo boolean::negate($var); |
Beta Was this translation helpful? Give feedback.
-
@nibra echo ((new Boolean('yes')) != (new Boolean('on'))); |
Beta Was this translation helpful? Give feedback.
-
As discussed in this comment, it might be useful to add a package that deals with type conversions.
This discussion is used to evaluate the possible scope and other details of such a package.
Beta Was this translation helpful? Give feedback.
All reactions