简体   繁体   中英

Forcing case sensitive functions in PHP :: by re-compiling the source?

UPDATED
Is there any way to force case sensitive function names in PHP, even if it means re-compiling PHP?

  • could this be achieved by some setting in the php.ini ?
  • is it possible to achieve this by using some form of name-space "hack"?
  • as a last resort: how (and where) do I edit the PHP C / C++ source-code that could force global case-sensitivity --and make it available as an option in the php.ini -which could be overridden by apache config, and .htaccess , and during runtime with ini_set() ?

There are plenty answers that confirm:

  • PHP function-names and class-names are NOT case-sensitive
  • PHP constants and variable names ARE case-sensitive

This question is about taking control of the situation as it is quite painful if you have the following problem:

<?
    define('List', ':List:');
    die(List);
?>

Parse error : syntax error, unexpected ')', expecting '('

In the example above, the "intrinsic" function-name list interferes with the "user-defined" constant List and not in a "good" way - as it results in a Parse Error .

I know many PHP developers do not care too much about "case-sensitivity" and do not see the need for this; however, if you're building a neat boiler-plate, or a framework with well defined data-types as short words (for comparison reasons), then it is a problem as you are targeting a large audience.

Any input would be appreciated, thanks.

Finding clues on the net on how exactly to do this seems illusory; however, the following may be useful for anyone looking for clues in achieving something related.

To modify & compile the PHP source-code, see this article:

How to modify the php source code and recompile it?


Here's a few pointers that may be useful:

  • download the PHP source-code from here: http://php.net/downloads.php
  • have a look in the main "engine" folders for files that reference sensitiv & case_ in their contents; however, it is likely in here: ./Zend/zendAPI.c (citation needed)
  • take note of the constant CONST_CS and its value, defined in ./Zend/zend_constants.h file as it is used frequently
  • edit what you see fit, compile the updated code and copy+paste the necessary components into your main PHP runime folder, (in linux it is most likely in: /etc/php

To make your changes be configurable in php.ini

  • you will need to edit the ./Zend/zend_ini.c file
  • add your setting as a function in there
  • make sure it's defined & referenced where necessary, as in the ./Zend/zend_ini_scanner.* files.

To make your changes be configurable in Apache config & .htaccess



Question specific

The above may be helpful for re-building PHP, but, there may be a better and much quicker solution.

Constructive criticism
Related to the nature this question specifically, editing & re-compiling the source may be overkill. Not only is it completely out of "PHP language" scope, but mentioning that this is targeted a large audience may defeat the purpose of the framework / boilerplate entirely.

A better approach
The exact reason for why it is so crucial for case-sensitivity of these exact data-type constant words is unknown; however, maybe re-naming them, or defining functions to use in stead of constant comparison could be beneficial, so:

  • instead of the word: List , how about ListDT (for List-Data-Type)
  • comparison may be longer to type than a short function like: isList()

After all: "speed of coding" could be more important than "speed of code" in many cases.

This approach may prevent the need for re-compiling PHP and the "target audience" won't need to manually obtain and install a very specific PHP version just because "the framework" demands some specific words.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM