Static call members must be defined as static (PHP5ONLY) tip: PHP5 introduces the concept of static members, which is consistent with the internal static variables of PHP4 functions, however, the former is used as a member of the class. Static variables and Ruby class variables (the members of the classvari static call must be defined as static (PHP5 ONLY)
Tip: PHP 5 introduces the concept of static members, which is used in the same way as the static variables in PHP 4 functions, but the former is used as a member of the class. Static variables are similar to class variable in Ruby. all class instances share the same static variables.
QUOTE:
// Php code Highliting for CU by dZ902
bar();// static wayfoo::bar();?>
Static calling uses non-static members, which is 50-60% slower than static calling. This is mainly because the former generates an E_STRICT warning and the internal switch is also required.
Tips for using a class constant (PHP5 ONLY): New features of PHP 5, similar to const of C ++.
The benefit of using a class constant is:
-No additional overhead for parsing during compilation
-The pooled tables are smaller, so internal search is faster.
-The class constant only exists in the specified "namespace", so the name of the miscellaneous is shorter.
-Code cleaner to make debugging easier
(Temporarily) do not use require/include_once
Require/include_once will open the target file every time it is called!
-If the absolute path is used, PHP 5.2/6.0 does not have this problem.
-The new APC cache system has solved this problem.
File I/O increase => efficiency reduction
If necessary, you can manually check whether the file has been require/include.
Do not use a function when a meaningless function has a corresponding constant.
Although not used much, the efficiency is improved by about 3500%. The fastest Win32 check:
-No function is required.
-Win98/NT/2000/XP/Vista/Longhorn/Shorthorn/Whistler... General
-Always available
Time problem (PHP> 5.1.0 ONLY) how do you know the current time in your software? Simple: "time () again, you ask me ...」.
However, it is always slow to call a function.
Now, we can use $ _ SERVER ['request _ time'] to save the trouble of calling a function.
Accelerate PCRE-use (?
In this way, PHP does not need to allocate memory for the corresponding content, saving the cost. Efficiency is improved by about 15%.
-Regular expressions are not required. read the "string functions" section of the manual during analysis. Are there any useful functions you missed?
For example:
Strpbrk ()
Strncasecmp ()
Strpos ()/strrpos ()/stripos ()/strripos ()
Accelerate strtr
If all the characters to be converted are single characters, use strings instead of arrays for strtr:
'e', // ... )); // bad?>
Efficiency improvement: 10 times.
Do not replace the str_replace parameter. Very slow! Solution:
-Use strpos to search for it (very fast) and check whether it needs to be replaced. if necessary, replace it.
Efficiency:
-To replace: the efficiency is almost the same, with a difference of about 0.1%.
-If no replacement is required: use strpos to increase speed by 200%.
Evil @ operator
Do not abuse the @ operator. Although @ looks simple, there are actually many operations in the background. Compared with @, the efficiency difference is 3 times.
In particular, do not use @ in a loop. in five loop tests, even if the error is disabled with error_reporting (0), enabling it after the loop is completed is faster than using.
Use strncmp
Use strncmp/strncasecmp instead of substr/strtolower to compare the first n characters, not to mention ereg. Strncmp/strncasecmp is the most efficient (although not high ).
Use substr_compare (PHP5 ONLY) with caution)
As mentioned above, substr_compare should be faster than substr. The answer is no, unless:
-Case-insensitive comparison
-Relatively large string
Do not use constants instead of strings.
Why:
-You need to query the duplicate table twice.
-You need to convert the constant name to lowercase (when performing the second query)
-Generate an E_NOTICE warning.
-A temporary string is created.
Efficiency difference: 700%.
Do not place count/strlen/sizeof in the for loop condition statement tip: my personal practice
Efficiency improvement:
-Count 50%
-Strlen 75%:
Short code is not necessarily fast
Which one do you think is faster?
Efficiency comparison:
-Longest: 4.27
-Longer: 4.43
-Short: 4.76
Incredible? Next:
read()) !== false) { if ($entry == '.' || $entry == '..') { continue; }}// versusglob('./*');// versus (include . and ..)scandir('.');?>
Which one is faster?
Efficiency comparison:
-Original: 3.37
-Glob: 6.28
-Scandir: 3.42
-Original without OO: 3.14
-SPL (PHP5): 3.95
Voiceover: from now on, we can see that PHP5's object-oriented efficiency has improved a lot, and the efficiency is not much worse than pure functions.
Improve PHP file access efficiency
When other PHP files need to be included, use the full path or the relative path that is easy to convert.
Best use
PHP has many extensions and functions available. before implementing a function, check whether PHP has this function? Is there a simpler implementation?
Tips for referencing can be:
-Simplified access to complex structure data
-Optimized memory usage