Skip to content
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

Fix PHP warnings #431

Open
jaragunde opened this issue Dec 1, 2018 · 16 comments
Open

Fix PHP warnings #431

jaragunde opened this issue Dec 1, 2018 · 16 comments

Comments

@jaragunde
Copy link
Member

jaragunde commented Dec 1, 2018

There is a number of PHP warnings/notices in the web server log. These are just some of them:

[11-Sep-2018 11:24:37 UTC] PHP Notice:  Undefined offset: 0 in /var/www/html/phpreport/model/dao/ExtraHourDAO/PostgreSQLExtraHourDAO.php on line 126
[11-Sep-2018 11:24:37 UTC] PHP Notice:  Undefined index:  in /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 409
[11-Sep-2018 11:24:37 UTC] PHP Notice:  session_start(): A session had already been started - ignoring in /var/www/html/phpreport/util/LoginManager.php on line 149
[11-Sep-2018 11:24:38 UTC] PHP Notice:  Undefined index: sid in /var/www/html/phpreport/web/services/getProjectsService.php on line 34

They should be checked one by one and addressed.

jaragunde added a commit that referenced this issue Dec 1, 2018
There were several errors like this in the logs:

PHP Warning:  Use of undefined constant header - assumed 'header'
(this will throw an Error in a future version of PHP) in
/var/www/html/phpreport/web/services/getProjectUserWeeklyHoursReportJsonService.php on line 168
jaragunde added a commit that referenced this issue Dec 1, 2018
There were several errors like this in the logs:

PHP Notice:  Undefined index: dateFormat in
/var/www/html/phpreport/web/services/getProjectUserWeeklyHoursReportJsonService.php on line 41

Used the new PHP7 null coalesce operator to assign default
values in those cases that printed a warning. Also removed
$login which was never used in these services.
jaragunde added a commit that referenced this issue Dec 1, 2018
Fixes this warning which popped up several times:
PHP Notice:  Undefined variable: login in
/var/www/html/phpreport/web/viewProjectDetails.php on line 345

The login parameter was ignored by the service, and the local $login
var didn't even have a value.
jaragunde added a commit that referenced this issue Dec 1, 2018
Follow-up to 0d6c7e2 and
b181615.

As explained there, it is unnecessary and it also caused an 'undefined
index' php warning being logged.
jaragunde added a commit that referenced this issue Dec 1, 2018
The output of this value was always 0, and it was also generating some
php warnings:
PHP Notice:  Undefined variable: report2 in
/var/www/html/phpreport/web/services/getProjectUserCustomerReportJsonService.php on line 135
PHP Warning:  count(): Parameter must be an array or an object that
implements Countable in
/var/www/html/phpreport/web/services/getProjectUserCustomerReportJsonService.php on line 135
jaragunde added a commit that referenced this issue Dec 1, 2018
Using is_null on an array element evaluates if the contents of that
position in the array is null, assuming the element exists, and emits
a warning if it doesn't.

Using isset checks the existence of that element, which is what we
actually want.

Fixes warnings like this, logged from many phpreport pages:
PHP Notice:  Undefined index:  in
/var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 409
jaragunde added a commit that referenced this issue Dec 17, 2018
(Merge pull request #424 from Igalia/php-warnings-project-details)
@jaragunde
Copy link
Member Author

A number of patches addressing this kind of issues was merged in PR #424:

commit e5e16885d3a3483d868738e9d3fcd98473ac394f
Merge: f6a48312 2dc4214c
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Mon Dec 17 09:09:08 2018 +0100

    [#431] Address some PHP warnings in project details report
    
    (Merge pull request #424 from Igalia/php-warnings-project-details)

commit 2dc4214cc68cfe3f617082c726942d62d82837d6 (origin/php-warnings-project-details, php-warnings-project-details)
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Tue Sep 4 16:54:43 2018 +0200

    [#431] Fix some 'undefined index' warnings in PostgreSQLTaskDAO.
    
    Using is_null on an array element evaluates if the contents of that
    position in the array is null, assuming the element exists, and emits
    a warning if it doesn't.
    
    Using isset checks the existence of that element, which is what we
    actually want.
    
    Fixes warnings like this, logged from many phpreport pages:
    PHP Notice:  Undefined index:  in
    /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 409

commit 7817586f8ecc13c1650c7d4f89f1ec6bcdd76b0a
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Tue Sep 4 15:30:39 2018 +0200

    [#431] Fix 'total' value in getProjectUserCustomerReportJsonService.
    
    The output of this value was always 0, and it was also generating some
    php warnings:
    PHP Notice:  Undefined variable: report2 in
    /var/www/html/phpreport/web/services/getProjectUserCustomerReportJsonService.php on line 135
    PHP Warning:  count(): Parameter must be an array or an object that
    implements Countable in
    /var/www/html/phpreport/web/services/getProjectUserCustomerReportJsonService.php on line 135

commit 38ee69ed390082b773637d4a2f82ae8f01c5f098
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Tue Sep 4 15:22:20 2018 +0200

    [#431] Remove explicit session management from viewProjectDetails.
    
    Follow-up to 0d6c7e2ec62fb3513a5f63688512c1c353bf5683 and
    b181615db5011d2725ef4ef73ddf38106b54ebb9.
    
    As explained there, it is unnecessary and it also caused an 'undefined
    index' php warning being logged.

commit bbfb5108da5598679c75ee3f9bb89a5a92b34286
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Tue Sep 4 14:51:02 2018 +0200

    [#431] Fix several 'undefined variable' warnings.
    
    Fixes this warning which popped up several times:
    PHP Notice:  Undefined variable: login in
    /var/www/html/phpreport/web/viewProjectDetails.php on line 345
    
    The login parameter was ignored by the service, and the local $login
    var didn't even have a value.

commit 0f30c55a299494dc605f4d1cbf2a86165e9faf83
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Tue Sep 4 14:32:30 2018 +0200

    [#431] Fix several 'undefined index' warnings.
    
    There were several errors like this in the logs:
    
    PHP Notice:  Undefined index: dateFormat in
    /var/www/html/phpreport/web/services/getProjectUserWeeklyHoursReportJsonService.php on line 41
    
    Used the new PHP7 null coalesce operator to assign default
    values in those cases that printed a warning. Also removed
    $login which was never used in these services.

commit 54f798a7f2222f97fcf55575e4d78392b50cead0
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Tue Sep 4 14:24:18 2018 +0200

    [#431] Fix several 'undefined constant' warnings.
    
    There were several errors like this in the logs:
    
    PHP Warning:  Use of undefined constant header - assumed 'header'
    (this will throw an Error in a future version of PHP) in
    /var/www/html/phpreport/web/services/getProjectUserWeeklyHoursReportJsonService.php on line 168

jaragunde added a commit that referenced this issue Jan 14, 2019
Fixes the following errors:
Undefined offset: 0 in /var/www/html/phpreport/model/dao/UserGoalDAO/PostgreSQLUserGoalDAO.php on line 224
Undefined offset: 0 in /var/www/html/phpreport/model/dao/ExtraHourDAO/PostgreSQLExtraHourDAO.php on line 126
Undefined variable: rows in /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 461
Undefined variable: result in /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 645
Undefined variable: string in /var/www/html/phpreport/web/services/createTasksService.php on line 234
sizeof(): Parameter must be an array or an object that implements Countable in /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 669
jaragunde added a commit that referenced this issue Jan 14, 2019
Fixes errors like:
Undefined index: sid in /var/www/html/phpreport/web/services/getUserTemplatesService.php on line 26
jaragunde added a commit that referenced this issue Jan 14, 2019
Fixes the following errors:
Undefined offset: 0 in /var/www/html/phpreport/model/dao/UserGoalDAO/PostgreSQLUserGoalDAO.php on line 224
Undefined offset: 0 in /var/www/html/phpreport/model/dao/ExtraHourDAO/PostgreSQLExtraHourDAO.php on line 126
Undefined variable: rows in /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 461
Undefined variable: result in /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 645
Undefined variable: string in /var/www/html/phpreport/web/services/createTasksService.php on line 234
sizeof(): Parameter must be an array or an object that implements Countable in /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 669
jaragunde added a commit that referenced this issue Feb 25, 2019
(Merge pull request #438 from Igalia/i431-php-warnings-tasks-page)
@jaragunde
Copy link
Member Author

jaragunde commented Feb 25, 2019

More fixes from PR #438:

commit aa71d450708497e0a07872609681d32bd3af1e7f 
Merge: 060e65bb d0369116
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Sun Feb 24 22:44:49 2019 -0800

    [#431] Address some PHP warnings in tasks page.
    
    (Merge pull request #438 from Igalia/i431-php-warnings-tasks-page)

commit d0369116dfaeb89092ea68226db0e2d83b32d92d
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Mon Jan 14 13:01:53 2019 +0100

    [#431] Fix other PHP warnings in tasks page.
    
    Fixes the following errors:
    Undefined offset: 0 in /var/www/html/phpreport/model/dao/UserGoalDAO/PostgreSQLUserGoalDAO.php on line 224
    Undefined offset: 0 in /var/www/html/phpreport/model/dao/ExtraHourDAO/PostgreSQLExtraHourDAO.php on line 126
    Undefined variable: rows in /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 461
    Undefined variable: result in /var/www/html/phpreport/model/dao/TaskDAO/PostgreSQLTaskDAO.php on line 645
    Undefined variable: string in /var/www/html/phpreport/web/services/createTasksService.php on line 234
    sizeof(): Parameter must be an array or an object that implements Countable in /var/www/html/phpreport/model/dao/T
askDAO/PostgreSQLTaskDAO.php on line 669

commit 5ed74aff024b01b90df5eac5179a6ffaceb25ebe
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Mon Jan 14 12:44:39 2019 +0100

    [#431] Fix several 'undefined index' errors related with GET parameters.
    
    Fixes errors like:
    Undefined index: sid in /var/www/html/phpreport/web/services/getUserTemplatesService.php on line 26

jaragunde added a commit that referenced this issue May 5, 2021
Also fix indentation of surrounding code.
jaragunde added a commit that referenced this issue May 5, 2021
Also fix indentation of surrounding code.
jaragunde added a commit that referenced this issue May 5, 2021
Also fix indentation of surrounding code.
jaragunde added a commit that referenced this issue May 20, 2021
Merge pull request #497 from Igalia/i431-php-warnings
@jaragunde
Copy link
Member Author

More fixes from PR #497:

commit 07d723e7dfa3bd8776964a9eb0d6fac291f9fa41
Merge: 7c8f2bed 873f6f14
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Thu May 20 13:53:58 2021 +0200

    [#431] Fix PHP warnings in task delete and project update.
    
    Merge pull request #497 from Igalia/i431-php-warnings

commit 873f6f143372119699eb8cf4d8a6ba179ee2f6f4 
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Wed May 5 13:07:58 2021 +0200

    [#431] Fix PHP warnings during project update operation.
    
    Also fix indentation of surrounding code.

commit 50728ee1ca77bd68357714fc1c2b7b969016b454
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Wed May 5 13:04:36 2021 +0200

    [#431] Fix PHP warnings during task delete operation.

anarute pushed a commit to anarute/phpreport that referenced this issue Jul 27, 2021
anarute pushed a commit to anarute/phpreport that referenced this issue Jul 27, 2021
anarute added a commit to anarute/phpreport that referenced this issue Jul 27, 2021
jaragunde added a commit that referenced this issue Jan 25, 2022
Fixes:
* Undefined index: sid, uid, active, login, order
* Undefined variable: string
@jaragunde
Copy link
Member Author

Reviewed in #551:

06a1e578 [#431] Fix PHP warnings in customer management page. [Jacobo Aragunde Pérez]

Reviewed in #553:

d8b73be8 [#431] Fix 'undefined variable: string' in sector services. [Jacobo Aragunde Pérez]

jaragunde added a commit that referenced this issue Jan 25, 2022
Fixes several of each type:
* Use of undefined constant.
* Undefined variable.
* Undefined index.
* Invalid argument supplied for foreach().
* count(): Parameter must be an array.
jaragunde added a commit that referenced this issue Jan 25, 2022
Fixes:
* Undefined variable: createTasks
* count(): Parameter must be an array
jaragunde added a commit that referenced this issue Jan 25, 2022
Fixes several of each type:
* Use of undefined constant.
* Undefined variable.
* Undefined index.
* Invalid argument supplied for foreach().
* count(): Parameter must be an array.
jaragunde added a commit that referenced this issue Jan 25, 2022
Fixes:
* Undefined variable: createTasks
* count(): Parameter must be an array
@jaragunde
Copy link
Member Author

Reviewed in #555:

2c7e97a7 [#431] Fix undefined index warnings in user tasks report. [Jacobo Aragunde Pérez]
ff4e96c4 [#431] Fix warnings when failed to create a task. [Jacobo Aragunde Pérez]
73d65833 [#431] Fix warnings in user details report. [Jacobo Aragunde Pérez]

jaragunde added a commit that referenced this issue Feb 7, 2022
Fixes:
* Undefined variable: string
* Undefined index: sid
@jaragunde
Copy link
Member Author

Reviewed in PR #560:

bc8dbff6 [#431] Fix warnings in area-related services. [Jacobo Aragunde Pérez]

jaragunde added a commit that referenced this issue Apr 7, 2022
Fixes:
* Undefined index: sid
* Undefined variable: string
@jaragunde
Copy link
Member Author

jaragunde commented Apr 19, 2022

Merged in PR #575:

1976c0e9 [#431] Fix PHP warnings in hour compensation management page. [Jacobo Aragunde Pérez]

Also, recently pushed to main:

commit e88429e9f1b9ed47e474b923a92218e9398f6b2b
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Thu Apr 7 16:01:48 2022 +0200

    [#431] Prevent 'undefined variable: sid' in getTaskTypes.

jaragunde added a commit that referenced this issue Apr 19, 2022
* Undefined index: format
* Undefined index: pid
* Undefined index: sid (twice)
* Undefined index: PHP_AUTH_USER
* Undefined offset: 0 (twice)
* Undefined variable: results (twice)
* Undefined variable: records (twice)
* Undefined variable: rows
* Undefined variable: stories
* Undefined variable: userLogin
* Undefined variable: userPassword

And other warnings derived from the above.
jaragunde added a commit that referenced this issue Apr 19, 2022
* Undefined index: format
* Undefined index: pid
* Undefined index: sid (twice)
* Undefined index: PHP_AUTH_USER
* Undefined offset: 0 (twice)
* Undefined variable: results (twice)
* Undefined variable: records (twice)
* Undefined variable: rows
* Undefined variable: stories
* Undefined variable: userLogin
* Undefined variable: userPassword

And other warnings derived from the above.
@jaragunde
Copy link
Member Author

Landed in PR #578:

commit 3a7c48af472243d85ef149a9ed854a158e2d6430
Author: Jacobo Aragunde Pérez <[email protected]>
Date:   Tue Apr 19 09:55:10 2022 +0200

    [#431] Fix PHP warnings.
    
    * Undefined index: format
    * Undefined index: pid
    * Undefined index: sid (twice)
    * Undefined index: PHP_AUTH_USER
    * Undefined offset: 0 (twice)
    * Undefined variable: results (twice)
    * Undefined variable: records (twice)
    * Undefined variable: rows
    * Undefined variable: stories
    * Undefined variable: userLogin
    * Undefined variable: userPassword
    
    And other warnings derived from the above.

@jaragunde
Copy link
Member Author

Merged in PR #600:

84a31455 Fix SessionID cannot be changed when a session is active in warning [Ana Rute Mendes]

@jaragunde
Copy link
Member Author

Merged in PR #606:

d1f0e6c6 [#431] Fix PHP warnings in city-related services. [Jacobo Aragunde Pérez]

jaragunde added a commit that referenced this issue Mar 8, 2023
This warning has become an error in PHP 8. We also remove some
unused code.
@jaragunde
Copy link
Member Author

Merged in PR #621:

4d307f27 [#431] Fix calling sizeof on non-countable. [Jacobo Aragunde Pérez]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants