


Analysis of the bug that the PHP error suppressor (@) causes failure to pass parameters by reference_PHP Tutorial
Look at the example below:
$array = array(1 ,2,3);
function add (&$arr) {
$arr[] = 4;
}
add(@$array);
print_r($array);
/**
At this time, $array has not changed, output:
Array
(
[0] => 1
[1] => 2
[2] => 3
)
*/
add($array);
print_r($array);
/**
Without error suppression, the output is normal:
Array
(
[0] => 1
[1] => 2
[2] => ; 3
[3] => 4
)
*/
?>
I have never encountered this problem before, so I first looked for relevant information to see if there is any ready-made answer. After searching on Google, I found that although someone has reported a similar bug to PHP: http:// bugs.php.net/bug.php?id=47623, but PHP official has not solved it yet and has not given a reply.
There is no way, I can only analyze it myself. I have introduced the principle of error suppression in the article before (In-depth understanding of PHP principles of error suppression and embedded HTML). In principle, error suppression only modifies error_reporting level, it stands to reason that it will not affect the function calling mechanism between contexts. This can only be done through field testing.
After gdb tracking, it was found that after using the wrong transplantation operator, the parameter opcode before the function call is different:
//When the error suppressor is not used
OPCODE = SEND_REF
//After the error suppressor is used
OPCODE = SEND_VAR_NO_RE
Initial problem Positioned, but what is the reason for this difference?
Since the OPCODE is different, it must have taken different branches during the syntax analysis stage. Thinking of this level, the problem is solved Positioned,
It turns out that in the PHP syntax analysis stage, entries in the form of "@" + expr are reduced to expr_without_variable, and the meaning of this kind of node is the value without a variable, that is, a literal value. We We all know that literal values cannot be passed by reference (because it is not a variable), so this difference will result.
The specific process is as follows:
1. Syntax analysis stage:
expr_without_variable:
//...with omission
| '@' { zend_do_begin_silence(&$1 TSRMLS_CC); }
expr { zend_do_end_silence(&$1 TSRMLS_CC); $$ = $3; }
//The ZEND_SEND_VAL branch is gone here
non_empty_function_call_parameter_list:
expr_without_variable { ....} // I mistakenly took this branch
| variable {..... } //Normal situation
So different OPCODEs are generated during compilation, which also leads to the appearance of problems.
Finally, I have explained the reason on this bug page of PHP. If you are interested, you can check out my poor English. Finally, thank you cici netizen for providing this interesting question.

ThesecrettokeepingaPHP-poweredwebsiterunningsmoothlyunderheavyloadinvolvesseveralkeystrategies:1)ImplementopcodecachingwithOPcachetoreducescriptexecutiontime,2)UsedatabasequerycachingwithRedistolessendatabaseload,3)LeverageCDNslikeCloudflareforservin

You should care about DependencyInjection(DI) because it makes your code clearer and easier to maintain. 1) DI makes it more modular by decoupling classes, 2) improves the convenience of testing and code flexibility, 3) Use DI containers to manage complex dependencies, but pay attention to performance impact and circular dependencies, 4) The best practice is to rely on abstract interfaces to achieve loose coupling.

Yes,optimizingaPHPapplicationispossibleandessential.1)ImplementcachingusingAPCutoreducedatabaseload.2)Optimizedatabaseswithindexing,efficientqueries,andconnectionpooling.3)Enhancecodewithbuilt-infunctions,avoidingglobalvariables,andusingopcodecaching

ThekeystrategiestosignificantlyboostPHPapplicationperformanceare:1)UseopcodecachinglikeOPcachetoreduceexecutiontime,2)Optimizedatabaseinteractionswithpreparedstatementsandproperindexing,3)ConfigurewebserverslikeNginxwithPHP-FPMforbetterperformance,4)

APHPDependencyInjectionContainerisatoolthatmanagesclassdependencies,enhancingcodemodularity,testability,andmaintainability.Itactsasacentralhubforcreatingandinjectingdependencies,thusreducingtightcouplingandeasingunittesting.

Select DependencyInjection (DI) for large applications, ServiceLocator is suitable for small projects or prototypes. 1) DI improves the testability and modularity of the code through constructor injection. 2) ServiceLocator obtains services through center registration, which is convenient but may lead to an increase in code coupling.

PHPapplicationscanbeoptimizedforspeedandefficiencyby:1)enablingopcacheinphp.ini,2)usingpreparedstatementswithPDOfordatabasequeries,3)replacingloopswitharray_filterandarray_mapfordataprocessing,4)configuringNginxasareverseproxy,5)implementingcachingwi

PHPemailvalidationinvolvesthreesteps:1)Formatvalidationusingregularexpressionstochecktheemailformat;2)DNSvalidationtoensurethedomainhasavalidMXrecord;3)SMTPvalidation,themostthoroughmethod,whichchecksifthemailboxexistsbyconnectingtotheSMTPserver.Impl


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

SublimeText3 Chinese version
Chinese version, very easy to use

Dreamweaver CS6
Visual web development tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

SublimeText3 Mac version
God-level code editing software (SublimeText3)
