EarthDay Posted September 2, 2022 Share Posted September 2, 2022 Hi All, I have upgraded my test server to PHP 8 and I am having an issue with my yearly staff holiday script (works out how many hours / minutes have been taken and how many left) and firstly gave me the below error message; Fatal error: Uncaught TypeError: Unsupported operand types: int - string in After a bit of Google and SO, I think that this has been solved by adding (int) to the - string. I am now getting the below error message; Fatal error: Uncaught TypeError: Unsupported operand types: string / int in Anything that I have tried from SO and Google does not appear to be working. Original Code <?php $time = $holiday_remain_time['total_year_holiday_hours_complete']; $total_year_holiday_hours = $holiday_remain_time['total_year_holiday_hours'] * 60; $remaining = ($total_year_holiday_hours - $holiday_remain_time['total_year_holiday_hours_complete']); $minutes = $holiday_remain_time['total_year_holiday_hours_complete']; $hours = floor($minutes/60).'.'. ($minutes % 60); $showHours = floor($minutes/60).' Hour '. ($minutes % 60) . ' Minute'; $reminutes = $remaining; $reshowHours = floor($reminutes/60).' Hour '. ($reminutes % 60) . ' Minute'; ?> Modified Code <?php $time = $holiday_remain_time['total_year_holiday_hours_complete']; $total_year_holiday_hours = $holiday_remain_time['total_year_holiday_hours'] * 60; $remaining = ((int)$total_year_holiday_hours - (int)$holiday_remain_time['total_year_holiday_hours_complete']); $minutes = $holiday_remain_time['total_year_holiday_hours_complete']; $hours = floor($minutes/60).'.'. ($minutes % 60); $showHours = floor($minutes/60).' Hour '. ($minutes % 60) . ' Minute'; $reminutes = $remaining; $reshowHours = floor($reminutes/60).' Hour '. ($reminutes % 60) . ' Minute'; ?> Database `id` int(11) NOT NULL, `user_id` int(100) DEFAULT NULL, `total_year_holiday_hours` varchar(100) DEFAULT NULL, `total_year_holiday_hours_complete` varchar(100) DEFAULT NULL Output Example Yearly Holiday : 40 Hours Already Holiday Taken : 15 Hours Remaining Holiday Hour: 25 Hours Display code <tbody> <?php foreach($holiday_activity as $record){ $hour = $record['hour'] * 60; $minutes = $hour + $record['minute']; $hours = intdiv($minutes, 60).' Hour '. ($minutes % 60) . ' Minute'; ?> <tr> <td><?php $date = $record['date']; $bits = explode('-', $date); $date = $bits[2] . '/' . $bits[1] . '/' . $bits[0]; echo $date; ?></td> <td><?php $date = $record['end_date']; $bits = explode('-', $date); $date = $bits[2] . '/' . $bits[1] . '/' . $bits[0]; echo $date; ?></td> <td><?= $hours; ?></td> <td><?php echo $record['status']; ?></td> <td> <?php if($record['status'] == 'active'){ echo 'cannot change'; } else{ ?> <a href="" class="btn btn-primary" data-toggle="modal" data-target="#staticBackdrop<?php echo $record['id']; ?>"> Edit </a> <!-- <a href="delete.php" class="btn btn-warning">Cancel</a> --> <?php } ?> </td> </tr> I have changed the database columns to INT and ran var_dump($hours); which shows NULL before the Modified Code above. If I run var_dump($hours); after the Modified Code, it shows nothing. Thanks, ED. Quote Link to comment https://forums.phpfreaks.com/topic/315263-upgrading-script-to-php-8-from-74-issues/ Share on other sites More sharing options...
cyberRobot Posted September 2, 2022 Share Posted September 2, 2022 Have you tried outputting $holiday_remain_time, to make sure it contains the expected values for "total_year_holiday_hours_complete" and "total_year_holiday_hours"? If not, try adding the following after the variable is defined: print '<pre>' . print_r($holiday_remain_time, true) . '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/315263-upgrading-script-to-php-8-from-74-issues/#findComment-1600000 Share on other sites More sharing options...
EarthDay Posted September 6, 2022 Author Share Posted September 6, 2022 Hi All, cyberRobot - thanks for your advice, the expected outputs were been returned. I have managed to resolve this by adding (INT); Example: $minutes = (INT)$hour + (INT)$record['minute']; Thanks, ED. Quote Link to comment https://forums.phpfreaks.com/topic/315263-upgrading-script-to-php-8-from-74-issues/#findComment-1600188 Share on other sites More sharing options...
Barand Posted September 6, 2022 Share Posted September 6, 2022 Why weren't they numeric to start with? Quote Link to comment https://forums.phpfreaks.com/topic/315263-upgrading-script-to-php-8-from-74-issues/#findComment-1600191 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.