User tests: Successful: Unsuccessful:
Added a check for the $user object in ActionLogPlugin to prevent PHP warnings when getIdentity() returns null.
Since reproducing a scenario where getIdentity() returns null via the UI is difficult please use the following script to verify the fix:
Create a test file test_actionlog_null.php
<?php
// Simulate scenario where getIdentity() returns null (guest user or logout scenario)
$user = null;
echo "TEST 1: Before fix (shows PHP warning)\n";
echo "Attempting to access \$user->id when \$user is null:\n";
try {
$id = $user->id; // Old code behavior
echo "User ID: " . $id . "\n";
} catch (\Error $e) {
echo "❌ PHP Warning: " . $e->getMessage() . "\n\n";
}
echo "TEST 2: After fix (no warning)\n";
echo "Using null-safe operator:\n";
$id = $user?->id; // Fixed code behavior
$username = $user?->username ?? '';
echo "User ID: " . ($id ?? 'null') . "\n";
echo "Username: " . ($username ?: 'empty') . "\n";
echo "✅ No warnings - fix works correctly\n";
php test_actionlog_null.php
Expected output:
TEST 1 shows a PHP error when accessing properties on null
TEST 2 shows no warnings and handles null safely
PHP warnings when ActionLog runs without authenticated user.
No PHP warnings; gracefully handles null user.
| Status | New | ⇒ | Pending |
| Category | ⇒ | Administration |
@Shauryan0207 - I am trying to test your PR and I read the Testing Instructions of "PHP warnings when ActionLog runs without authenticated user" but I must admit not understanding what you meant as I can't think of anything that triggers an ActionLog without a user being authenticated (but that could just be ME not thinking through all of the cases)...
I could imagine maybe this happening if a Session timeout happened during an action, but that's not so easy to trigger.
Looking forward to specific use case that I can test for you.
Hey @richard67
Create a test file test_actionlog_null.php
<?php
// Simulate scenario where getIdentity() returns null (guest user or logout scenario)
$user = null;
echo "TEST 1: Before fix (shows PHP warning)\n";
echo "Attempting to access \$user->id when \$user is null:\n";
try {
$id = $user->id; // Old code behavior
echo "User ID: " . $id . "\n";
} catch (\Error $e) {
echo "❌ PHP Warning: " . $e->getMessage() . "\n\n";
}
echo "TEST 2: After fix (no warning)\n";
echo "Using null-safe operator:\n";
$id = $user?->id; // Fixed code behavior
$username = $user?->username ?? '';
echo "User ID: " . ($id ?? 'null') . "\n";
echo "Username: " . ($username ?: 'empty') . "\n";
echo "✅ No warnings - fix works correctly\n";
php test_actionlog_null.php
Expected output:
TEST 1 shows a PHP error when accessing properties on null
TEST 2 shows no warnings and handles null safely
| Labels |
Added:
PR-5.4-dev
|
||
| Category | Administration | ⇒ | Administration Modules Front End |
| Category | Administration Modules Front End | ⇒ | Administration |
I have tested this item ✅ successfully on 998963d
Review
@Shauryan0207 Could you adjust the testing instructions in the description (initial post) of this PR to the latest code changes? Thanks in advance.
@Shauryan0207 Could you adjust the testing instructions in the description (initial post) of this PR to the latest code changes? Thanks in advance.
@richard67 Done ! Thanks
@Shauryan0207 I'm probably doing something incorrectly but I'm not matching the BEFORE condition of a PHP error.
I created the php file: test_actionlog_null.php in the root of the sub-folder where Joomla 5.4 is installed, /_j540/
I connected to an SSH terminal and ran from the /_j540/ root, php test_actionlog_null.php and received this result:
TEST 1: Before fix (shows PHP warning)
Attempting to access $user->id when $user is null:
User ID:
TEST 2: After fix (no warning)
Using null-safe operator:
User ID: null
Username: empty
✅ No warnings - fix works correctly
What did I screw up? ;(
I looked at this PR and I am not happy with it. The quoted test would just show the desired behaviour. It does not test Joomla. Various CLI commands such as php cli/joomla.php site:up don't trigger the plugin. It seems to me it may be better to see the PHP warning so that the site owner can see that something unusual is going on. Can you provide any sort of screenshot showing the warning?
@Shauryan0207 I'd prefer to have instructions for a real test, not just code review.
Providing reproducible test instructions would also show that you have tested the changes from your PR yourself before submitting it, which is a mandatory requirement for contributing here.
Could you provide instructions? Thanks in advance.