简体   繁体   English

如何在PHP中创建类似“ echo”的语言构造函数

[英]how to create language constructors in PHP like 'echo'

I was looking for creating some thing like: 我正在寻找创建类似的东西:

myprint 'Hello';

In questions like Q1 , Q2 i saw some people that saying: 在诸如Q1Q2之类的问题中 ,我看到有人说:

  • It is impossible 是不可能的
  • It is possible 有可能的

Actually i want to know can i create such language constructor that does something by editing php interpreter? 其实我想知道我可以创建这样的语言构造函数,通过编辑php解释器来做什么吗?

If yes, how? 如果是,怎么办?

The solution I've done for same situation (not actual Language Constructor , but useful for your question): 我针对相同情况所做的解决方案(不是实际的Language Constructor ,但对您的问题很有用):

1) open php.ini and uncomment auto_prepend_file settings, and set like this: auto_prepend_file =C:\\wamp\\my_prepended_functions.php 1)打开php.ini并取消注释auto_prepend_file设置,并进行如下设置:auto_prepend_file = C:\\ wamp \\ my_prepended_functions.php

2) put this content in that .php file: 2)将此内容放在该.php文件中:

if(!function_exists('v'))   { function v() { foreach(func_get_args() as $each){ var_dump($each); }    } }
if(!function_exists('vx'))  { function vx(){ foreach(func_get_args() as $each){ var_dump($each); } exit;} }

3) restart server and you will be able to always execute in any php file: 3)重新启动服务器,您将能够始终在任何php文件中执行:

v($myVar1);
v($myVar1,$myVar2 );
vx($myVar1);

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

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