0

I have Zend Server 6.3 and Php 5.4 on Windows. And system works very well. Now I moved code to live site, which runs Php 5.3.29 on Ubuntu Server with DirectAdmin. All other website are running well there. But my current website gives me this error (the site is on WordPress 4.3):

Warning: mysql_connect(): Headers and client library minor version mismatch.
Headers:50541 Library:50623 in /home/cheapauto/domains/*DOMAIN*/public_html/wp-includes/wp-db.php on line 1482
Parse error: syntax error, unexpected '[' in /home/*USER*/domains/*DOMAIN*/public_html/wp-content/plugins/*MY-PLUGIN*/includes/final.class.NRSBooking.php on line 101 

The line is this:

$now = explode(' ', microtime())[1];

And my whole plugin function is this:

private function getIncrementalHash($length = 5)
{
    //$charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
    $charset = "ABCDEFGHIJKLMNPRSTUVYZ"; // fits LT & EN, O is skipped to similarity to Zero
    $charsetLength = strlen($charset);
    $result = '';

    $now = explode(' ', microtime())[1];
    while ($now >= $charsetLength)
    {
        $i = $now % $charsetLength;
        $result = $charset[$i] . $result;
        $now /= $charsetLength;
    }
    return substr($result, -$length);
}

Any ideas how to make it work on live site?

As per Php reference http://php.net/manual/en/function.microtime.php it says:

microtime() returns the current Unix timestamp with microseconds. This function is only available on operating systems that support the gettimeofday() system call.

And I use that function to generate unique new booking code:

$newBookingCode = "R".$validNextMySQLInsertId."A".$this->getIncrementalHash(5);

Thank you!

KestutisIT
  • 195
  • 3
  • 13

1 Answers1

2

Array dereferencing, i.e. getting results from function which returns array like:

$now = explode(' ', microtime())[1];

is available since php5.4

For php5.3 and older use:

$now = explode(' ', microtime());
$now = $now[1];
u_mulder
  • 51,564
  • 5
  • 39
  • 54