Is it able to "extend" the existing function in PHP

37 views Asked by At

I'm working on a PHP file which was encrypted with ionCube.

I only have the document about the function list of the class like this:

  • class User
    • addUser($name)
    • deleteUser($id)
    • etc.

I want to add a log entry after each function is called, to trace that what function is called.

I know that I can use the magic method __call when I write the class like:


    public function __call($name, $arguments)
        {
            // Add the Log Function here 
        }

However, the project is encrypted. It is illegal if I decrypt the file and replace it, So I need to override or extend the current class in the raw file page.

For example:


    // index.php
    
    include "bootstrap.php"; // Manage the Classes
    ..
    ..
    
    // Add Something like this
    
    User->__call = function($name, $arguments){
     sendAlert($name, $arguments);
     User->__call($name, $arguments); // Call original function if they already have the logs/ other action
    }

Then I will get the log Like this:

    11:00am [User] addUser: peter
    11:00am [User] editUser: peter
    11:00am [User] setPermission: admin
    11:00am [User] saveToDatabase
    ...
    ...

Is it possible?

0

There are 0 answers