2

I'm trying to use override_function

http://php.net/manual/en/function.override-function.php from

http://pecl.php.net/package/apd but APD hasn't been updated since 2004 and no longer installs via PECL.

I tried to compile it using the patch listed in http://pecl.php.net/bugs/bug.php?id=16780&edit=2

It was successful but the compile directive I'm using

sudo /Applications/MAMP/bin/php5.3/bin/phpize CFLAGS='-O2 -arch i386 -arch ppc -g -Os' LDFLAGS='-O2 -arch i386 -arch ppc ' CXXFLAGS='-O2 -arch i386 -arch ppc -g -Os'

is creating a file with 64 bit architecture

 /tmp/apd/apd-1.0.1: file modules/apd.so 
  modules/apd.so: Mach-O 64-bit bundle x86_64`

I've no idea why it's not working - but this has become a super long detour for a function I might just be able to override some other way.

  override_function('header', '$a', 'echo $a;');
Alex C
  • 16,624
  • 18
  • 66
  • 98
  • 1
    have you not thought about using namespaces to encapsulate your functions – RobertPitt Jan 27 '11 at 21:10
  • sadly, the production version of PHP is pre namespaces. I'm running PHPUnit to execute unit tests against code that's going to go into production. Maybe adding an SO is just as bad - but I thought staying away from namespace was the safest way to test. – Alex C Jan 27 '11 at 21:23

2 Answers2

4

Another possibility is using runkit_function_redefine.

Note, that the PECL version of runkit is from 2006, while there's a newer version on github.

See also: Redefine Built in PHP Functions

Community
  • 1
  • 1
Sebastian Paaske Tørholm
  • 49,493
  • 11
  • 100
  • 118
0

This worked for me: Get the latest apd source from the PECL homepage. Patch it with the mentioned patch, phpize, make, make test, make install. And follow the instructions to load the module.

$ file apd-1.0.1/module/apd.so:

apd-1.0.1/modules/apd.so: ELF 32-bit LSB shared object, Intel 80386, version 1 (SYSV), dynamically linked, not stripped

php -v gives me:

PHP 5.3.5-1ubuntu7.2 with Suhosin-Patch (cli) (built: May  2 2011 23:18:30) 
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
    with Advanced PHP Debugger (APD) v1.0.1, , by George Schlossnagle
Glaslos
  • 2,872
  • 1
  • 21
  • 31