overriding utils.php

hi
I want to add functionality to the file util.php (include/utils.php). I added this file to the custom directory (custom/include/utils.php) and rebuilt from the admin panel but the program does not use this file and uses the old one.
someone knows how to overidde files like this? is that even possible?
also I would like to override SearchForm2.php

Your file should be called custom/include/custom_utils.php (you called it custom/include/utils.php instead).

Alternatively there is a more appropriate way to add functionnality to utils.php:
you can create one or more files in: custom/Extension/application/Ext/Utils/.php where is the name you decide. In this way you reduce the risk of your files being overwritten when upgrading or adding a new module.

For reference have a look here:
http://support.sugarcrm.com/Documentation/Sugar_Developer/Sugar_Developer_Guide_6.5/Extension_Framework/Extensions/Utils/

Additionnally, I believe that, using one of the two methods described above you could also try using the php function runkit_function_redefine to redefine, hence override, a function that has already been defined in utils.php.
Php reference here:
http://php.net/manual/it/function.runkit-function-redefine.php

1 Like

thank you that worked.
but then I added the file to custom/Extension/application/Ext/Utils/.php , xdebug didn’t break at this file. it breaks in other files but not at that one.

does it work with a js file?