Analysis of predefined variables in PHP which is not commonly used but very practical

  • 2021-12-12 04:06:51
  • OfStack

1. $php_errormsg-First error message


<?php

@strpos();

echo $php_errormsg;

?>

2. $http_response_header-HTTP response header


<?php

function get_contents() {

 file_get_contents("http://example.com");

 var_dump($http_response_header);

}

get_contents();

var_dump($http_response_header);

?>

3. $argc-Number of parameters passed to script


<?php

var_dump($argc);

?>

 When using this command to execute : php script.php arg1 arg2 arg3

4. $argv-Array of parameters passed to script


<?php

var_dump($argv);

?>

 When using this command to execute: php script.php arg1 arg2 arg3
__FILE__: Returns the path file name and file name __DIR__: Returns the full directory of the file __LINE__: Returns the line number of the current file code __CLASS__: Returns the current class name __FUNCTION__: Returns the current method name __METHOD__: Returns the current class and method names

var_dump(__FILE__); // Path file name and file name    E:\demo\blog_code\predefined\predefined.php
var_dump(__DIR__); // Complete directory in which          E:\demo\blog_code\predefined
var_dump(__LINE__); // Line number of code          4
class testClass{
  function testMethod(){
    var_dump(__FUNCTION__); // Returns the current method name   testMethod
    var_dump(__CLASS__);  // Returns the class name      testClass
    var_dump(__METHOD__);  // Class name plus method name    testClass::testMethod
  }
}
 
$a=new testClass();
$a->testMethod();


Related articles: