Re: Re: Trouble interpreting error message

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




On Dec 9, 2015, at 5:35 PM, Ryan Pallas wrote:

On Wed, Dec 9, 2015 at 6:23 PM, Jeffry Killen <jekillen@xxxxxxxxxxx> wrote:

Hello, again:

In the original post I was trying to apply anonymous code to a static
member array.

            self::$_runList[$_what] = $_code;
$_out = self::$_runList[$_what]($_params); // >>> line # 27
referred to in error message

What is now working is to use a locally declared array inside run()
instead:

$_runList = array()
$_runList[$_what] = $_code;
return $_runList[$_what]($_params);

Apparently, php doesn't like doing this with a static member array
variable.

Thanks to anyone who spent some time with the original post.
JK






You appear to be using a 5.x version of PHP. This is an associativity
problem and can be resolved by upgrading to PHP7. Here is your original code, you can see it works in PHP7, and produces and notice followed by a
fatal error in PHP<7  https://3v4l.org/Zu1jO For more information, see
http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.variable-handling.indirect

I have also been testing out the use of non static member variable array referenced via $this-> that is working. The non static member array appears to be retaining the code that is assigned to it, as I can call it again in a subsequent call and it runs as expected, using the original array key string assigned to it.

// yes, it is PHP Version 5.6.0 running under Apache 2.4x on FreeBSD 10.01

$_fileSelf = basename($_SERVER['PHP_SELF']);
if($_fileSelf == 'index.php')
  {
   $_fileSelf = './';
  }

class _DEV
      {
       private static $_className = '';
       private        $_runList = array();
       private static $_codeSaved = array();
       public function __construct()
              {
               self::$_className = get_class($this);
              }

       public function run($_what, $_code, $_params)
              {
               $_errHead = self::$_className." -> ".__FUNCTION__;
               $_out = array();
               if($_code !== '')
                 {
                  self::$_codeSaved[$_what] = $_code;
                  $this->_runList[$_what] = $_code;
                 }
               $_out = $this->_runList[$_what]($_params);
               return $_out;
              }

      }

$_trial = new _DEV();

$_test_1 = function()
         {
          $_out = array();
          $_out['1_passed'] = "Appears";
          return $_out;
         };

$_test_2 = function()
         {
          $_out = array();
          $_out['2_passed'] = " to be ";
          return $_out;
         };

$_test_3 = function()
         {
          $_out = array();
          $_out['3_passed'] = "working";
          return $_out;
         };

$_resArray = array();
$_resArray[0] = $_test_1;
$_resArray[1] = $_test_2;
$_resArray[2] = $_test_3;

$_display = '';

if($_GET['try'] == 'true')
  {
   for($_itr = 0; $_itr < 3; $_itr++)
      {
       $_out = '';
       $_out = $_trial->run('try-'.($_itr + 1), $_resArray[$_itr], '');
       $_display .= $_out[($_itr+1)."_passed"]."\n";
      }
   $_extra = array();
   $_extra = $_trial->run('try-2', '', '');
   $_display .= "\nextra: ".$_extra['2_passed'];
  }

/*
 $_display prints:
Appears
 to be
working

extra:  to be
*/



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux