简体   繁体   中英

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:

  • It is impossible
  • It is possible

Actually i want to know can i create such language constructor that does something by editing php interpreter?

If yes, how?

The solution I've done for same situation (not actual Language Constructor , but useful for your question):

1) open php.ini and uncomment auto_prepend_file settings, and set like this: auto_prepend_file =C:\\wamp\\my_prepended_functions.php

2) put this content in that .php file:

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:

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

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