[Vtigercrm-developers] A question on efficiency/semantics...
Mariusz Krzaczkowski | YetiForce Sp. z o.o.
m.krzaczkowski at yetiforce.com
Thu May 6 05:17:15 GMT 2021
Notice: Undefined variable / Undefined index / Undefined offset
This is a bug that causes a lot of problems,
no one knows if it's on purpose or if someone forgot to change something
or made a typo.
https://stackoverflow.com/questions/4261133/notice-undefined-variable-notice-undefined-index-and-notice-undefined#answer-4261200
From the vast wisdom of the PHP Manual [6]:
> Relying on the default value of an uninitialized variable is
> problematic in the case of including one file into another which uses
> the same variable name. It is also a major security risk [1] with
> register_globals [2] turned on. E_NOTICE [3] level error is issued in
> case of working with uninitialized variables, however not in the case
> of appending elements to the uninitialized array. isset() [4] language
> construct can be used to detect if a variable has been already
> initialized. Additionally and more ideal is the solution of empty() [5]
> since it does not generate a warning or error message if the variable
> is not initialized.
--
Z poważaniem / Kind regards
Mariusz Krzaczkowski
W dniu 2021-05-05 17:36, Alan Lord napisał(a):
> Interesting.
>
> That seems like good/valid Warning - it should encourage the
> declaration of variables at the start of each routine.
>
> Maybe for a variable variable it might not make sense but those aren't
> that common it seems to me?
>
> Nice to hear from you Joe. Hope all's well.
>
> Cheers
>
> Al
>
> On 05/05/2021 16:24, Joe Bordes wrote:
>
>> Sadly, PHP warning system doesn't work that way:
>>
>> ----
>>
>> <?php
>> error_reporting(-1);
>> ini_set('display_errors', 1);
>>
>> if ($nothere) {
>> echo "it is here";
>> } else {
>> echo "it isn't here";
>> }
>> -----
>>
>> result
>>
>> -----
>>
>> joe at linuxmint:/var/www/coreBOSTest$ php k.php
>> PHP Notice: Undefined variable: nothere in /var/www/coreBOSTest/k.php
>> on line 5
>> PHP Stack trace:
>> PHP 1. {main}() /var/www/coreBOSTest/k.php:0
>>
>> Notice: Undefined variable: nothere in /var/www/coreBOSTest/k.php on
>> line 5
>>
>> Call Stack:
>> 0.0001 393600 1. {main}() /var/www/coreBOSTest/k.php:0
>>
>> it isn't here
>>
>> ------
>>
>> so you get the warning if the variable is not defined which is what
>> you are trying to avoid
>
> _______________________________________________
> http://www.vtiger.com/
Links:
------
[1] http://www.php.net/manual/en/security.globals.php
[2] http://www.php.net/manual/en/ini.core.php#ini.register-globals
[3]
http://www.php.net/manual/en/errorfunc.constants.php#errorfunc.constants.errorlevels.e-notice
[4] http://www.php.net/manual/en/function.isset.php
[5] http://php.net/manual/en/function.empty.php
[6] http://php.net/manual/en/language.variables.basics.php#example-112
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.vtigercrm.com/pipermail/vtigercrm-developers/attachments/20210506/aca058e1/attachment.html>
More information about the vtigercrm-developers
mailing list