Illegal offset type in

I’ve just moved my script to new server running php7 (from server running php5.3) and I’m getting following warming:

Warning: Illegal offset type in C:\inetpub\wwwroot\script.php on line 23

Warning refers to those lines from the script below:
[php]
$timeStamp[$row->cusLastEdited] = $row->cusTimestamp;
$timeStamp[$row->locLastEdited] = $row->locTimestamp;
$timeStamp[$row->jobAllLastEdited] = $row->jobAllTimestamp;
[/php]

And the array ends up to be empty.
Any help would be greatly appreciated.

[php]

$query = sqlsrv_query($link,"
SELECT $valLocation, $valContact, $valCustomers, LOC.LocationID, CUS.PrivateNotes, CUS.CustomerID, CUS.LastEdited AS cusLastEdited, LOC.LastEdited AS locLastEdited, JALL.LastEdited AS jobAllLastEdited, JACT.isActiveJobStartDate, JACT.StartTime, JACT.ArriveWindow, JCOM.isCompleteJobStartDate, JFIRSTCOM.isFirstServiceDate,

CONVERT ( varchar , CUS.LastEdited , 112 ) + CONVERT ( varchar , CUS.LastEdited , 108 ) AS cusTimestamp,
CONVERT ( varchar , LOC.LastEdited , 112 ) + CONVERT ( varchar , LOC.LastEdited , 108 ) AS locTimestamp,
CONVERT ( varchar , CUS.BirthDate , 112 ) + ‘T’ + CONVERT ( varchar , CUS.BirthDate , 108 ) AS birthTimestamp,
JALL.jobAllTimestamp

FROM tblCustomers CUS
// the query goes on…
");
errorCheck($query);

while ($row = sqlsrv_fetch_object($query)) {
$CustomerID = $row->CustomerID;
$ExtraId = $row->Extra26;

// reset the array
$timeStamp = array();

// Select the most recent LastEdited value
$timeStamp[$row->cusLastEdited] = $row->cusTimestamp;
$timeStamp[$row->locLastEdited] = $row->locTimestamp;
$timeStamp[$row->jobAllLastEdited] = $row->jobAllTimestamp;

$maxTimeStamp = max($timeStamp);
$timeStamp = array_flip($timeStamp);
$maxLastEdited = $timeStamp[$maxTimeStamp];

}
[/php]

What does the array keys contain? ($row->cusLastEdited etc)

date and time stamps.

Could you try to var_dump($row->cusLastEdited) so we can see exactly what it contains? If it contains a datetime string or a timestamp it should work, if it contains a datetime object or similar then we might have problems as you can’t have an object as an array key

This is what I get:

object(DateTime)#4 (3) {
[“date”]=>
string(26) “2016-10-23 13:40:21.000000”
[“timezone_type”]=>
int(3)
[“timezone”]=>
string(15) “America/Chicago”
}

I get the same warning on PHP 5.3. What do you expect the output array to look like?

[php]$timeStamp[$row->cusLastEdited] = $row->cusTimestamp;[/php]

Should probably be something like

[php]$timeStamp[/* some date string or timestamp here? */] = $row->cusTimestamp;[/php]

if so then just use the format method on the datetime object to get whichever key you need

This is the output I got from:
[php]print_r($timeStamp);[/php]
on the php 5.3 machine.

Array
(
[Jan 25 2016 01:52:21:000PM] => 2016012513:52:21
[Jan 31 2011 10:54:35:773AM] => 2011013110:54:35
[Oct 24 2016 09:22:57:180AM] => 2016102409:22:57
)

And same on php7 machine shows the array empty:

Array
(
)

Sponsor our Newsletter | Privacy Policy | Terms of Service