On the problem of the destructor of PHP

Source: Internet
Author: User
Directly on the code

class FileTest extends SplFileInfo{    public function __destruct(){        var_dump($this->getRealPath());    }}$file = new FileTest('index.php');  //boolean falsenew FileTest('index.php');  //'E:\Apache24\htdocs\index.php'

As the above code shows, the same new object, assigned to the variable and not assigned to the variable result is not the same, does anyone know why?

Reply content:

Directly on the code

class FileTest extends SplFileInfo{    public function __destruct(){        var_dump($this->getRealPath());    }}$file = new FileTest('index.php');  //boolean falsenew FileTest('index.php');  //'E:\Apache24\htdocs\index.php'

As the above code shows, the same new object, assigned to the variable and not assigned to the variable result is not the same, does anyone know why?

I ran out of the PHP5.6 under the result:

D:\PHP5.6\php.exe E:\M5\carvincai\test\file.phpbool(false)bool(false)

Can you give me some more detailed information?

Update:

I modified the code:


  
   getRealPath());    }}$file = new FileTest(__FILE__);  //boolean falsenew FileTest(__FILE__);  //'E:\Apache24\htdocs\index.php'

Results:

D:\PHP5.6\php.exe E:\M5\carvincai\test\file.phpstring(29) "E:\M5\carvincai\test\file.php"string(29) "E:\M5\carvincai\test\file.php"

Master, would you please check the file name in the constructor again?

PHP 5.6 Environment No problem, consistent results
First make sure that the ' index.php ' file is present
You must have executed under the same environment, using the ' index.php ' as the parameter passed in?

  • 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.