From: Operating system: All (seen under Linux) PHP version: 5.3.8 Package: Compile Warning Bug Type: Feature/Change Request Bug description:char* field should be const char* to avoid C++ warning
Description: ------------ http://news.php.net/php.internals/55662 I'm writing a C++ extension to PHP. When declaring a INI entry I get the following warning, multiple times: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] This only arises when compiling with a C++ compiler. The right and easy fix seems to set some fields to const char *. Some may even be set to const char * const (but this alternative seems to be used nowhere). The proposed patch is against the php5-dev-5.3.8-2 package of debian sid: PHP 5.3.8-2 with Suhosin-Patch (cli) (built: Sep 12 2011 07:28:26) Test script: --------------- Write a C++ extension: config.m4 should contain PHP_REQUIRE_CXX(). Declare your module: zend_module_entry quezako_module_entry = { STANDARD_MODULE_HEADER, "YourExtensionName", // (1 warning here) [...], "0.42", // (1 warning here) [...], STANDARD_MODULE_PROPERTIES_EX }; Declare an INI entry: PHP_INI_BEGIN() STD_PHP_INI_ENTRY( "extensionName.variable", // (1 warning here) "default value", // (1 warning here) [...] ) PHP_INI_END() Expected result: ---------------- No compilation warning. Actual result: -------------- Multiple of the following warning: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings] Using the very common fix of prepending (char*) to the string constant is especially harmful here, because of ZEND_INI_ENTRY3_EX using sizeof() on in: it returns 4/8 (32/64bits platform). Using a cast to char[] solves the problem, but the above fix is a very very common mistake. If the target fields were const char*, no compilation warning would be rose. -- Edit bug report at https://bugs.php.net/bug.php?id=55835&edit=1 -- Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=55835&r=trysnapshot54 Try a snapshot (PHP 5.3): https://bugs.php.net/fix.php?id=55835&r=trysnapshot53 Try a snapshot (trunk): https://bugs.php.net/fix.php?id=55835&r=trysnapshottrunk Fixed in SVN: https://bugs.php.net/fix.php?id=55835&r=fixed Fixed in SVN and need be documented: https://bugs.php.net/fix.php?id=55835&r=needdocs Fixed in release: https://bugs.php.net/fix.php?id=55835&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=55835&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=55835&r=needscript Try newer version: https://bugs.php.net/fix.php?id=55835&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=55835&r=support Expected behavior: https://bugs.php.net/fix.php?id=55835&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=55835&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=55835&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=55835&r=globals PHP 4 support discontinued: https://bugs.php.net/fix.php?id=55835&r=php4 Daylight Savings: https://bugs.php.net/fix.php?id=55835&r=dst IIS Stability: https://bugs.php.net/fix.php?id=55835&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=55835&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=55835&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=55835&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=55835&r=mysqlcfg