[GH-ISSUE #1866] cannot access private method #798

Closed
opened 2026-03-04 02:18:06 +03:00 by kerem · 8 comments
Owner

Originally created by @buexplain on GitHub (Jan 5, 2024).
Original GitHub issue: https://github.com/Seldaek/monolog/issues/1866

Monolog version 3

PHP Warning:  Invalid callback Monolog\Handler\RotatingFileHandler::customErrorHandler, cannot access private method Monolog\Handler\RotatingFileHandler::customErrorHandler()
Originally created by @buexplain on GitHub (Jan 5, 2024). Original GitHub issue: https://github.com/Seldaek/monolog/issues/1866 Monolog version 3 ```php PHP Warning: Invalid callback Monolog\Handler\RotatingFileHandler::customErrorHandler, cannot access private method Monolog\Handler\RotatingFileHandler::customErrorHandler() ```
kerem 2026-03-04 02:18:06 +03:00
  • closed this issue
  • added the
    Bug
    label
Author
Owner

@Seldaek commented on GitHub (Apr 12, 2024):

This is weird.. I can't reproduce it (https://3v4l.org/ZHA87) and I don't really see why it would do this as the callback is only used within the context of StreamHandler /cc @corentin-cres

<!-- gh-comment-id:2051247126 --> @Seldaek commented on GitHub (Apr 12, 2024): This is weird.. I can't reproduce it (https://3v4l.org/ZHA87) and I don't really see why it would do this as the callback is only used within the context of StreamHandler /cc @corentin-cres
Author
Owner

@lcharette commented on GitHub (Apr 13, 2024):

I was able to replicate this UserFrosting by removing write permission to the log file, which resulted in a similar error message :

Fatal error: Uncaught Error: Invalid callback Monolog\Handler\StreamHandler::customErrorHandler, cannot access private method Monolog\Handler\StreamHandler::customErrorHandler()

Using the example above (https://3v4l.org/ZHA87) on the same environment and on the same file (without write access) returned the proper output :

string(40) "Failed to open stream: Permission denied" string(9) "Test test" 

The difference is our app use a custom StreamWrapper. So the core PHP fopen isn't actually called by Monolog's StreamHandler, but our own. And both will invoke customErrorHandler, which won't work on our side since the method is private. Therefore, customErrorHandler must be public.

Note the actual process when customErrorHandler is public is similar to this :

  1. Monolog StreamHandler call fopen
  2. Our own StreamHandler calls fopen
  3. fopen trows an exception
  4. Our StreamHandler invoke customErrorHandler (even if we use @fopen), then do the rest of it's job and return false.
  5. Monolog invoke customErrorHandler again
<!-- gh-comment-id:2053738957 --> @lcharette commented on GitHub (Apr 13, 2024): I was able to replicate this UserFrosting by removing write permission to the log file, which resulted in a similar error message : ``` Fatal error: Uncaught Error: Invalid callback Monolog\Handler\StreamHandler::customErrorHandler, cannot access private method Monolog\Handler\StreamHandler::customErrorHandler() ``` Using the example above (https://3v4l.org/ZHA87) on the same environment and on the same file (without write access) returned the proper output : ``` string(40) "Failed to open stream: Permission denied" string(9) "Test test" ``` The difference is our app use a custom StreamWrapper. So the core PHP `fopen` isn't actually called by Monolog's StreamHandler, but our own. And **both** will invoke `customErrorHandler`, which won't work on our side since the method is private. Therefore, `customErrorHandler` must be **public**. Note the actual process when `customErrorHandler` is public is similar to this : 1. Monolog StreamHandler call `fopen` 2. Our own StreamHandler calls `fopen` 3. `fopen` trows an exception 4. Our StreamHandler invoke `customErrorHandler` (even if we use `@fopen`), then do the rest of it's job and return `false`. 5. Monolog invoke `customErrorHandler` **again**
Author
Owner

@lcharette commented on GitHub (Apr 13, 2024):

Here's a way to replicate : https://3v4l.org/PjtpI

(Forget the open_basedir restriction in effect error... that means it's working, simply I can't replicate a non-writable file on the editor)

There we go. Both should return "Failed to open stream" : https://3v4l.org/LsBph

<!-- gh-comment-id:2053744999 --> @lcharette commented on GitHub (Apr 13, 2024): ~~Here's a way to replicate : https://3v4l.org/PjtpI~~ ~~(Forget the `open_basedir restriction in effect` error... that means it's working, simply I can't replicate a non-writable file on the editor)~~ There we go. Both should return "Failed to open stream" : https://3v4l.org/LsBph
Author
Owner

@Seldaek commented on GitHub (Apr 13, 2024):

Great, thanks for the investigative work there! I guess maybe using a closure instead would be better, otherwise public method with an internal phpdoc.. Anyway I'll look at this next week

<!-- gh-comment-id:2053767128 --> @Seldaek commented on GitHub (Apr 13, 2024): Great, thanks for the investigative work there! I guess maybe using a closure instead would be better, otherwise public method with an internal phpdoc.. Anyway I'll look at this next week
Author
Owner

@Seldaek commented on GitHub (Apr 15, 2024):

@lcharette can you please check using dev-main if this problem is fixed for you?

<!-- gh-comment-id:2056382216 --> @Seldaek commented on GitHub (Apr 15, 2024): @lcharette can you please check using dev-main if this problem is fixed for you?
Author
Owner

@lcharette commented on GitHub (Apr 16, 2024):

I confirm problem is fixed with dev-main. Thanks !

<!-- gh-comment-id:2060088506 --> @lcharette commented on GitHub (Apr 16, 2024): I confirm problem is fixed with `dev-main`. Thanks !
Author
Owner

@Seldaek commented on GitHub (Apr 17, 2024):

Great

<!-- gh-comment-id:2060622791 --> @Seldaek commented on GitHub (Apr 17, 2024): Great
Author
Owner

@interactiveRob commented on GitHub (Sep 17, 2024):

just in case anyone else from Userfrosting winds up here and is wondering which log file @lcharette is talking about above. --

That would be the /logs/userfrosting.log file. In my case, the app did not have write permission on the log which triggered the same private method issue discussed here.

<!-- gh-comment-id:2356964229 --> @interactiveRob commented on GitHub (Sep 17, 2024): just in case anyone else from Userfrosting winds up here and is wondering which log file @lcharette is talking about above. -- That would be the `/logs/userfrosting.log` file. In my case, the app did not have write permission on the log which triggered the same private method issue discussed here.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/monolog#798
No description provided.