https://github.com/null93/php-nop
PHP extension that replaces any function with a NOP function
https://github.com/null93/php-nop
nop php php-extension
Last synced: 2 days ago
JSON representation
PHP extension that replaces any function with a NOP function
- Host: GitHub
- URL: https://github.com/null93/php-nop
- Owner: null93
- License: mit
- Created: 2024-11-14T05:42:56.000Z (over 1 year ago)
- Default Branch: master
- Last Pushed: 2024-11-19T02:24:59.000Z (over 1 year ago)
- Last Synced: 2025-03-16T14:49:34.772Z (over 1 year ago)
- Topics: nop, php, php-extension
- Language: M4
- Homepage:
- Size: 14.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
## PHP Extension — NOP
Sometimes you just want to disable the functionality of a build-in PHP function without touching code or using the `disable_functions` option which spits out a fatal error.
This extension is a proof of concept that allows you to replace any built-in function in PHP with a NOP (no operation) function.
The NOP replacement function does not return any value so it is not guaranteed to be a drop-in replacement for all functions.
## Installation
You can install this extension via the deb packages in the releases section.
For example, to install the extension for PHP 8.3 on an ARM64 machine, run the following:
```shell
curl -sLo ./php8.3-nop_arm64_0.1.0.deb https://github.com/null93/php-nop/releases/download/0.1.0/php8.3-nop_arm64_0.1.0.deb
apt install ./php8.3-nop_arm64_0.1.0.deb
```
Next, you will want to enable the extension in your PHP configuration file.
```ini
extension=nop.so
nop.functions=chmod,chown
```
Notice that `nop.functions` is a comma-separated list of functions that you want to replace with the NOP function.
## Development
Spin up a Docker container:
```shell
docker run -v `pwd`:/usr/src -w /usr/src --rm -it php:8.3-cli-alpine sh
```
Inside the container, run the following commands:
```shell
# Install build dependencies and build the extension
apk --update add php83-dev make g++
phpize && ./configure && make && make install
make test
# Manually test functionality
php -d 'extension=nop.so' -d 'nop.functions=' -r 'printf ("hi\n");'
php -d 'extension=nop.so' -d 'nop.functions=printf' -r 'printf ("hi\n");'
```
## Package Extension
Automatically packaged with NFPM and Github actions. Simply tag and push. If you need to manually package, run the following:
```shell
export VERSION=0.1.0
export PHP_VERSION=8.3
export ARCH=amd64
./scripts/nfpm-template > nfpm.yaml
nfpm pkg --packager deb --target php8.3_nop_amd64.deb
```
## Additional Resources
- https://www.phpinternalsbook.com/
- https://www.zend.com/sites/zend/files/pdfs/whitepaper-zend-php-extensions.pdf
- https://www.zend.com/resources/writing-php-extensions