简体   繁体   English

通过重新编译源代码在PHP ::中强制区分大小写的函数?

[英]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? 有没有办法在PHP中强制区分大小写的函数名称,即使它意味着重新编译PHP?

  • could this be achieved by some setting in the php.ini ? 这可以通过php.ini一些设置来实现吗?
  • is it possible to achieve this by using some form of name-space "hack"? 是否有可能通过使用某种形式的名称空间“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() ? 作为最后的手段:我如何(以及在​​哪里)编辑可能强制全局区分大小写的PHP C / C++源代码 - 并使其作为php.ini的选项可用 - 它可以被apache配置覆盖和.htaccess ,以及在运行时使用ini_set()

There are plenty answers that confirm: 有很多答案证实:

  • PHP function-names and class-names are NOT case-sensitive PHP函数名和类名不区分大小写
  • PHP constants and variable names ARE case-sensitive PHP常量和变量名称区分大小写

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 . 在上面的示例中,“内在”函数名称list干扰“用户定义”常量List而不是“良好”方式 - 因为它会导致解析错误

I know many PHP developers do not care too much about "case-sensitivity" and do not see the need for this; 我知道许多PHP开发人员并不太关心“区分大小写”,并且不需要这样做; 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: 要修改和编译PHP源代码,请参阅以下文章:

How to modify the php source code and recompile it? 如何修改php源代码并重新编译呢?


Here's a few pointers that may be useful: 这里有一些可能有用的指针:

  • download the PHP source-code from here: http://php.net/downloads.php 从这里下载PHP源代码: http//php.net/downloads.php
  • have a look in the main "engine" folders for files that reference sensitiv & case_ in their contents; 在主要的“引擎”文件夹中查看在其内容中引用sensitivcase_文件; however, it is likely in here: ./Zend/zendAPI.c (citation needed) 但是,它可能在这里: ./Zend/zendAPI.c (需要引证)
  • take note of the constant CONST_CS and its value, defined in ./Zend/zend_constants.h file as it is used frequently 记下常量CONST_CS及其值,在./Zend/zend_constants.h文件中定义,因为它经常使用
  • 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 编辑你认为合适的东西,编译更新的代码并将必要的组件复制+粘贴到你的主PHP runime文件夹中,(在linux中它很可能在: /etc/php

To make your changes be configurable in php.ini 要在php.ini配置您的更改

  • you will need to edit the ./Zend/zend_ini.c file 您需要编辑./Zend/zend_ini.c文件
  • add your setting as a function in there 将您的设置添加为功能
  • make sure it's defined & referenced where necessary, as in the ./Zend/zend_ini_scanner.* files. 确保在必要时定义和引用它,如./Zend/zend_ini_scanner.*文件。

To make your changes be configurable in Apache config & .htaccess 要使您的更改可以在Apache config和.htaccess进行配置



Question specific 问题具体

The above may be helpful for re-building PHP, but, there may be a better and much quicker solution. 以上内容可能有助于重新构建PHP,但是,可能会有更好,更快的解决方案。

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. 它不仅完全脱离“PHP语言”范围,而且提到这是针对大量受众可能完全打败框架/样板的目的。

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) 而不是单词: ListListDT怎么ListDT (对于List-Data-Type)
  • comparison may be longer to type than a short function like: isList() 比例可能比短函数更长,比如: 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. 这种方法可能会阻止重新编译PHP的需要,并且“目标受众”不需要手动获取和安装非常具体的PHP版本,因为“框架”需要一些特定的单词。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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