# php7ext-sample **Repository Path**: yunlong/php7ext-sample ## Basic Information - **Project Name**: php7ext-sample - **Description**: 使用 VS2015 为 PHP7.0 开发扩展的示例。 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2016-05-05 - **Last Updated**: 2020-12-19 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README #Sample Extension For PHP 7 This is a sample for PHP 7 extension, created by Visual Studio 2015 Community. ##Dependencies - Microsoft Visual Studio 2015 Community - PHP 7.0 RC6 Binaries For Windows - PHP 7.0 RC6 Sources ##Steps > PRJROOT is any a path you like, only if it's full accessible. 1. Unzip the PHP7 binaries to `PRJROOT\php7bin` 2. Unzip the sources code of PHP7 to `PRJROOT\php7src` 3. Clone this repository into `PRJROOT\php7ext-sample\` 4. Open the `PRJROOT\php7ext-sample\php7ext-sample.sln` by VS2015 5. Choose Win32/Win64 platform to complie 6. Copy the `php7ext-sample.dll` to `PRJROOT\php7\ext`, and turn it on in the php.ini 7. Copy `sample.php` to the directory of website and try it. ##How to create a new extension > You should install a bash-shell first, such as `msys`. 1. Add PHP binary root to shell path. ``` export PATH=$PATH:/PHPROOT/ ``` 2. Write the definitions of the output functions in `ABC.def` ``` string func1(int, string) int func2(float) ``` 3. Execute the `ext_skel_win32.php` to create an extension project. ``` php.exe /PHPSRCROOT/ext/ext_skel_win32.php --extname=NAME --proto=./ABC.def ``` 4. Use VS2015 to create a VC++ project from existing codes of it. 5. Configure the project, add the dependencies directories like `/PHPSRCROOT/TSRM`, `/PHPSRCROOT/main`, `/PHPSRCROOT/Zend`, `/PHPSRCROOT/win32`. 6. Add the C/C++ preprocessor constants ``` ZEND_DEBUG=0 PHP_EXTENSION PHP_WIN32 ZEND_WIN32 HAVE_NAME=1 // NAME should be replaced by ur extension name. COMPILE_DL_NAME // refer to above ZTS // Remove this if NTS ``` 7. Add the `/PHPROOT/dev/PHP7.lib` to Linker as import library. 8. Copy `/PHPSRCROOT/win32/build/config.w32.h.in` to `/PHPSRCROOT/main/config.w32.h`. ``` // For Windows Only: Add a line at the first line, before including any header files. #define PHP_COMPILER_ID "VC14" // VS2015 ``` 9. Now, it's done, you can try to compile && test it under PHP7. > Notices: > If you are creating a new extension for PHP7-Win64, you should watch out the > VC++ project type of x64 platform. In VC2015, it will be Execution even if > you have selected a DLL project, of x64 platform.