Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

cannot access private method #1866

Closed
buexplain opened this issue Jan 5, 2024 · 8 comments · May be fixed by #1875
Closed

cannot access private method #1866

buexplain opened this issue Jan 5, 2024 · 8 comments · May be fixed by #1875
Labels
Milestone

Comments

@buexplain
Copy link

Monolog version 3

PHP Warning:  Invalid callback Monolog\Handler\RotatingFileHandler::customErrorHandler, cannot access private method Monolog\Handler\RotatingFileHandler::customErrorHandler()
@Seldaek
Copy link
Owner

Seldaek commented 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

@lcharette
Copy link

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

@lcharette
Copy link

lcharette commented 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

@Seldaek
Copy link
Owner

Seldaek commented 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

@Seldaek
Copy link
Owner

Seldaek commented Apr 15, 2024

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

@lcharette
Copy link

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

@Seldaek
Copy link
Owner

Seldaek commented Apr 17, 2024

Great

@interactiveRob
Copy link

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.

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants