using return statements in class __construct method?

From: Date: Mon, 03 Nov 2014 01:20:36 +0000
Subject: using return statements in class __construct method?
Groups: php.general 
Request: Send a blank email to php-general+get-324025@lists.php.net to get a copy of this message
I understand that it is not possible for the __construct method to return a value itself, but is it legal to statically call a method inside the __construct() method that statically calls another method that does use the return statement? __construct statically calls method a method a statically calls method b; does not use return but just sets object properties. method b returns values to method a I would think that this would be valid. I have posted the code prior to debugging at http://stackoverflow.com/questions/26705965/does-php-oop-allow-return-statements-in-construct-functions-in-this-way However the current partial code is this: class _UPDATER
      {
       private static $_fontList = array();
       private static $_fontDir = 'fonts';
       private static $_ttfDir = 'new-fonts-ttf';
       private static $_eotDir = 'new-fonts-eot';
       private static $_ttfSubDirs = array();
       private static $_fontIndex = "fontIndex.php";
       private static $_cssFileInventory = "chooserDeclarations.css";
       private static $_error = '';
       public function __construct()
              {
               self::gather();
              }
       public function getError()
              {
               if(!self::$_error)
                 {
                  return 0;
                 }
               $_error = self::$_error;
               self::$_error = '';
               return $_error;
              }
       private function gather()
               {
                 $_error = '';
                 self::$_error = 'test one';
                /* the rest of the method code is commented out, the above is all that is being run now.
                  etc....*/
               }
As a side effect of trying to debug this, the following is the code that loads and instantiates the class code $_file_self = basename($_SERVER['PHP_SELF']); $_error = ''; $_stat = ''; if($_POST['proc'] == 'go') { if(!file_exists('class/updaterClass.php'))
     {
      $_error = 'updater class file not found';
     }
else if(!is_readable('class/updaterClass.php'))
     {
      $_error = "updater class file is not readable";
     }
else
     {
      $_ret = '';
      require_once('class/updaterClass.php');
      $_update = new _UPDATER();
      $_ret = $_update->getError();
      print $_ret; // <<<< notice this
      if($_ret)
        {
         $_error = $_ret;
        }
      else
        {
         $_stat = 'update successfull';
        }
      header('location:clear.php'); // dummy file that redirects back to the http_referer to clear post vars.
     }
} I have to use the print statement to get $_error set to $_ret value (at which time I also get an 'headers already sent' error message. The value of $_error is also print to the page where it is supposed to. Without the print statement, the $_ret value does not make it to the page. <!DOCTYPE html> <html> <head> <title>HTML 5 Embedded Fonts</title> <!-- <meta> --> <meta content="en-us" http-equiv="Content-Language"> <meta content="text/html: charset=utf-8" http-equiv="Content-Type"> <!-- <link rel="stylesheet" type="text/css" href="" media="screen"> --> <link rel="stylesheet" type="text/css" href="cssIndex.css" media="screen"> <link rel="stylesheet" type="text/css" href="embeddedFontDeclarations.css" media="screen"> <script type="text/javascript" src="js/upDater.js"></script> <script type="text/javascript"> var err = "<?php print $_error; ?>"; var stat = "<?php print $_stat; ?>"; var UD = new _UPDATE(); window.onload = function()
       {
        UD.init();
        var errStr = document.getElementById('err');
        if(err) // oops just saw a problem here
          {
           errStr.style.color = "#993333";
           errStr.childNodes[0].data += 'Status: '+err;
          }
        else if(stat)
          {
           errStr.childNodes[0].data += 'Status: '+stat;
          }
       }
</script> I know this is a bundle: Thanks for time and attention JK

« previous php.general (#324025) next »