- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP Spotting References
Introduction
Many syntax constructs in PHP are implemented via referencing mechanisms. If reference to a global variable is unset in a function, the same variable in global namespace is not removed.
Example
<?php $var1 = 'Hello World'; function myfunction(){ global $var1; $var2 =&$var1; echo "$var1, $var2
"; $var2="Hello PHP"; echo "$var1, $var2
"; unset($var1); } myfunction(); echo "$var1
"; ?>
Output
Global $va1 is intact.
Hello World, Hello World Hello PHP, Hello PHP Hello PHP
debug_zval_dump() function can be used if a variable has references to other variables
Advertisements