Jump to content

Recommended Posts

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.

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>';

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.