Publish a list of simple language structures that are confused with functions in php5.4.10.

Source: Internet
Author: User
Publish a list of language structures that are easy to be confused with functions in php5.4.10. here, only some languages that are easy to be confused are sent. Because there are a lot of language structures that do not need to be listed, it is too troublesome to query the manual one by one. In fact, all the definitions that can be found in zend_language_scanner.l are language structures. For example, if, for, class, function, global, send a list of language structures that are easy to confuse with functions in php 5.4.10.
Here we will only post some obfuscation-prone messages. Because there are a lot of language structures that do not need to be listed, it is too troublesome to query the manual one by one. In fact, all the definitions that can be found in zend_language_scanner.l are language structures. Such as if, for, class, function, global, including php start and end tags And those operators are all language structures.


Many of the following are incorrect functions:
Exit
Die
Return
Echo
Print
Eval
_ Halt_compiler
Include
Include_once
Require
Require_once
Isset
Empty
Unset
List

There are also some special constants that are part of the language structure, but they will follow the current environment for special processing at runtime, and their values are only meaningful locally, not global.

_ CLASS __
_ TRAIT __
_ FUNCTION __
_ METHOD __
_ LINE __
_ FILE __
_ DIR __
_ NAMESPACE __

These special constants will be bound at runtime. Take _ CLASS _ as the binding code is as follows:
 
  "__CLASS__" {
  
const char *class_name = NULL;

if (CG(active_class_entry)
&& (ZEND_ACC_TRAIT ==
(CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT))) {
/* We create a special __CLASS__ constant that is going to be resolved
   at run-time */
zendlval->value.str.len = sizeof("__CLASS__")-1;
zendlval->value.str.val = estrndup("__CLASS__", zendlval->value.str.len);
zendlval->type = IS_CONSTANT;
} else {
if (CG(active_class_entry)) {
class_name = CG(active_class_entry)->name;
}

if (!class_name) {
class_name = "";
}

zendlval->value.str.len = strlen(class_name);
zendlval->value.str.val = estrndup(class_name, zendlval->value.str.len);
zendlval->type = IS_STRING;
}
return T_CLASS_C;
}


When _ CLASS _ is called for the first time, the current information is loaded into the zendval struct, including its name, name length, value, and type.
You can see the note: We create a special _ CLASS _ constant that is going to be resolved at run-time
However, it should be noted that he will only bind to the class that was originally called, and the subclass that inherits from him will not be bound again. If you write a class a, define a method foo in it, call the special constant _ CLASS _, and then write a class B to inherit class a and inherit that method, when the subclass calls foo, the obtained name is the name of the parent class a, not the subclass. Most early explanatory languages do this, but I tested ruby, which dynamically rebinds the class based on the current call. Therefore, the name of class B is obtained. I have never tried python, but I don't know how to deal with it.

In addition, the differences between language structures and functions are as follows:
1. no return value.
2. some language structure parameters can be enclosed in parentheses (not all). For example, you can echo 123,456. you can include '/home/angryfrog/library/my_class.php ', return 1; die and exit can be followed by no parameters or parentheses. But eval, isset, and unset still need parentheses.
Php language structure
------ Solution --------------------
Thanks for sharing ..

Learn More
------ Solution --------------------
Does include return value?
When did you change it?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.