Upgrade PHP 7.2 to 7.4

Upgrade PHP 7.2 to 7.4

cpshartcpshart Posts: 246Questions: 49Answers: 5

Link to test case:
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:

Hi

I have just upgraded my PHP from 7.2 to 7.4 using PHP Selector on my cPanel wrongly expecting it to maintain the extensions checked when using 7.2. I should have created a screenshot of all the extensions, so I am experiencing unusual behaviour on some of my datatables.

Before detailing the issues which are likely to be as a result of not including necessary PHP extensions, I have attached my current PHP set-up on the server. Can someone advise me if I am missing any obvious essential extensions.

Note reverting back to 7.2 still results in issues, so I must be missing some extensions is my guess.

Any help is much appreciated.

Many Thanks

Colin

This question has accepted answers - jump to:

Answers

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    The majority of my datatables are working bar one in Edit Mode it is not showing the fields in the modal, which would indicate the PHP upgrade to 7.4 may be a red herring so to speak, apologies if I have wasted anyones time. I will keep investigating ...

    Thanks

    Colin

  • cpshartcpshart Posts: 246Questions: 49Answers: 5
    edited October 2020

    I am getting an error on one of my datatables when adding a new entry using the editor on a very simple table, which from a google search appears to be an issue with PHP 7.4, as it was not happening before my upgrade from 7.2->7.4.

    Notice: Trying to access array offset on value of type bool in /home/ukincome/public_html/Editor-PHP-1.9.5/controllers/dview-stock_portfolios.php on line 85
    {"data":[{"DT_RowId":"row_29","dm_portfolios":{"user_id":1,"code":"GBUJKKB","name":"gbuhku","portfolio_type":"DEA","reporting_status":"yes"}}],"debug":[{"query":"SELECT * FROM `dm_portfolios` WHERE
    

    so I may roll out PHP 7.4 to PHP 7.3 unless anyone has any suggestions on how to fix the issue with datatables.net.

    Many Thanks

    Colin

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    Notice: Trying to access array offset on value of type bool in /home/ukincome/public_html/Editor-PHP-1.9.5/controllers/dview-stock_portfolios.php on line 85

    So what does line 85 of your controller look like?

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    Hi tangerine

    Line 85 is the switch statement below, I can PM you access to my system if you need it, let me know..

    I was going to drop back to PHP 7.2 temporarily to confirm it was working before as an option to confirm the issue is related to PHP 7.4. I have spoken to my hosting provider, guru and they have confirmed that PHP 7.4 is a stable release.

            Field::inst( 'dm_portfolios.reporting_status' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'A reporting status is required' )
                ) )
                )
    
    
        ->validator( function ( $editor, $action, $data ) use ($userid) {
            global $subscription_plan_id;
            global $portfolio_limit;
            
            
            if ( $action === Editor::ACTION_CREATE || $action === Editor::ACTION_EDIT ) { //1
               foreach ( $data['data'] as $pkey => $values ) { //2
                        $count = $editor
                                ->db()
                                ->query('select')
                                ->get('*')
                                ->table('dm_portfolios')
                                ->where( function ( $q ) use ( $userid) {
                                $q->where( 'user_id', $userid);
                                } )
                                ->exec()
                                ->count();
    
                                $subscription_plan_id = $editor
                                ->db()
                                ->query('select')
                                ->get('subscription_plan_id')
                                ->table('wp_pms_member_subscriptions')
                                ->where( function ( $q ) use ( $userid) {
                                $q->where( 'user_id', $userid);
                                } )
                                ->exec()
                                ->fetch();
                                
                        switch ($subscription_plan_id['subscription_plan_id']) {
                            case "18649": /* Bronze Plan */
                                $portfolio_limit = 12;
                                break; 
                            case "18650": /* Silver Plan */
                                $portfolio_limit = 13;
                                break; 
                            case "18651": /* Gold Plan */
                                $portfolio_limit = 14;
                                break; 
                            default: 
                                $portfolio_limit = 12;
                                break; 
                        }
    
                            // subscription_plan_id     description     portfolio limit
                            // 18649                    Bronze Plan     6, 12
                            // 18650                    Silver Plan     7, 13
                            // 18651                    Gold Plan       8, 14
                            
                        if ($count == $portfolio_limit){ //3
                            return 'Upgrade to add more than '. $portfolio_limit . ' portfolios.';
                        } //3
    
    

    let me know if you need more information.

    Many Thanks

    Colin

  • cpshartcpshart Posts: 246Questions: 49Answers: 5
    edited October 2020

    Hi

    If I add a new Entry and then attempt to delete the entry the system produces the following error

    Notice: Undefined index: data in /home/ukincome/public_html/Editor-PHP-1.9.5/lib/Editor.php on line 1275
    
    Warning: Invalid argument supplied for foreach() in /home/ukincome/public_html/Editor-PHP-1.9.5/lib/Editor.php on line 1275
    {"data":[],"debug":[]}
    

    It also refers to deleting 0 rows, as if it is not aware of the id of the row ?

    Are you sure you wish to delete 0 rows?
    

    When I attempt to edit a row it does not display the data in the form

    Other datatables appear to work ok on my system.

    Regards

    Colin

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    Hi tangerine

    I have sent you a PM with full access to my system and the problem, if you need it.

    Thanks

    Colin

  • tangerinetangerine Posts: 3,365Questions: 39Answers: 395
    Answer ✓

    What are the contents of $subscription_plan_id at this point:

    switch ($subscription_plan_id['subscription_plan_id']) 
    

    ?

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    Hi tangerine

    subscription_plan_id :
    Notice: Trying to access array offset on value of type bool in /home/ukincome/public_html/Editor-PHP-1.9.5/controllers/dview-stock_portfolios.php on line 85
    
    Notice: Trying to access array offset on value of type bool in /home/ukincome/public_html/Editor-PHP-1.9.5/controllers/dview-stock_portfolios.php on line 86
    

    If you google the above error

    Trying to access array offset on value of type bool in PHP 7.4
    

    there are a number of people who have experienced the same issue when switch to PHP 7.4

    I have been trying to upgrade the libraries to the latest datatables.net libraries on my system at the same time, but I am unable to create or delete records from any of my tables or those that I have tested, so although I am not live yet I very keen to get it resolved.

    Thanks Colin

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    Hi tangerine

    If I comment out the whole validator section in the server script. I then add a new row say TEST and refresh, it displays the row, then if I Edit no data is shown on the form and if I Delete, the message above ... delete 0 rows is shown and pressing delete results in an error

    Notice: Undefined index: data in /home/ukincome/public_html/Editor-PHP-1.9.5/lib/Editor.php on line 1275
    
    Warning: Invalid argument supplied for foreach() in /home/ukincome/public_html/Editor-PHP-1.9.5/lib/Editor.php on line 1275
    {"data":[],"debug":[]}
    

    Colin

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    Hi

    Can someone help here as a matter of urgency please as the datatables aspect of my website which is the core element is broken, I cannot add and delete rows using the Editor for any of my tables after upgrading from PHP 7.2 to PHP 7.4, I have now reinstated the PHP to 7.2 default values as per the previous settings, but my tables editor is still not working as expected.

    Ultimately I will need to upgrade to PHP 7.4 being the latest stable version, this may be a red herring in relation to the problem.

    Any help or guidance would be much appreciated, I can provide online access to my system.

    Best Regards

    Colin

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    Hi

    To summarise the current status
    Rolled back to PHP 7.2, default extensions as previously set confirmed by my host
    Using Latest libraries given by debugger

    I have commented out the Global Validator Section, although it has been in place for months working.

    Some Datatable Editor scripts are working normally where Parent Child set-up exists
    Other Simple Datatable PHP scripts not working as expected

    If I can get the Stock Portfolios working a very simple table, then I should be able to fix the other ones which are failing

    https://www.dividendview.co.uk/stock-portfolios/
    

    I will need to send a PM to provide access to anyone investigating the problem on my system

    On adding a record and then deleting the record I am getting the error message

    Are you sure you wish to delete 0 rows?
    

    then in Chrome, Developer Tools, Preview

    Notice: Undefined index: data in /home/ukincome/public_html/Editor-PHP-1.9.5/lib/Editor.php on line 1275
    
    Warning: Invalid argument supplied for foreach() in /home/ukincome/public_html/Editor-PHP-1.9.5/lib/Editor.php on line 1275
    {"data":[],"debug":[]}
    

    If I edit a row, it does not populate the Code and Name in the form, it just populates the default values, not the values set on the row.

    client script

    <html>
    <head>
    <title>Stock Portfolios</title>
    
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.22/css/jquery.dataTables.min.css" />
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/buttons/1.6.5/css/buttons.dataTables.min.css" />
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/searchpanes/1.2.0/css/searchPanes.dataTables.min.css" />    
    <link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/select/1.3.1/css/select.dataTables.min.css" />
    <link rel="stylesheet" type="text/css" href="https://www.dividendview.co.uk/Editor-1.9.5/css/editor.dataTables.min.css" />
    <link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/css/select2.min.css">
    
    <script type="text/javascript"   src="https://code.jquery.com/jquery-3.5.1.js"></script>
    <script type="text/javascript"   src="https://cdn.datatables.net/1.10.22/js/jquery.dataTables.min.js"></script> 
    <script type="text/javascript"   src="https://cdn.datatables.net/searchpanes/1.2.0/js/dataTables.searchPanes.min.js"></script>  
    <script type="text/javascript"   src="https://cdn.datatables.net/buttons/1.6.5/js/dataTables.buttons.min.js"></script>
    <script type="text/javascript"   src="https://cdn.datatables.net/select/1.3.1/js/dataTables.select.min.js"></script>
    <script type="text/javascript"   src="https://www.dividendview.co.uk/Editor-1.9.5/js/dataTables.editor.js"></script>    
    <script type="text/javascript"   src="https://cdn.datatables.net/responsive/2.2.6/js/dataTables.responsive.min.js"></script>
    <script type="text/javascript"   src="https://cdnjs.cloudflare.com/ajax/libs/select2/4.0.2/js/select2.min.js"></script> 
    
    <script type="text/javascript"   src="https://cdnjs.cloudflare.com/ajax/libs/jszip/3.1.3/jszip.min.js"></script>
    <script type="text/javascript"   src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/pdfmake.min.js"></script>
    <script type="text/javascript"   src="https://cdnjs.cloudflare.com/ajax/libs/pdfmake/0.1.36/vfs_fonts.js"></script>
    <script type="text/javascript"   src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.html5.min.js"></script>
    <script type="text/javascript"   src="https://cdn.datatables.net/buttons/1.5.4/js/buttons.print.min.js"></script>       
        
        
    </head>
    
    <table id="stock_portfolios" class="display compact" style="width:100%">
    <thead>
    ... etc
    <script type="text/javascript">
    (function($) {
    /* 
    * change when upgrading the Version of the datatables.net PHP files
    */  
    var EDITOR_DIR = 'Editor-PHP-1.9.5';    
        
    var editor; // use a global for the submit and return data rendering in the examples
    var table;
        
    $(document).ready(function() {
        editor = new $.fn.dataTable.Editor( {
            ajax: {
                url: "../../" + EDITOR_DIR + "/controllers/dview-stock_portfolios.php",
                type: 'POST',
                data: function ( d ) {
                    d.userid = $('#passuserid').val();
                }
            },
            table: table,
            fields: [ {
                    label: "Portfolio:",
                    name: "dm_portfolios.code"
                }, {
                    label: "Name:",
                    name: "dm_portfolios.name"
                }, {
                    label: "Portfolio Type:",
                    name: "dm_portfolios.portfolio_type",
                    type:  "radio",
                    options: [
                        { label: "Dealing", value: "DEA" },
                        { label: "ISA",   value: "ISA" },
                        { label: "SIPP",   value: "SIPP" }
                        ],
                    def: "DEA"
                }, {
                    label: "Reporting Status:",
                    name: "dm_portfolios.reporting_status",
                    type:  "radio",
                    options: [
                        { label: "Yes", value: "yes" },
                        { label: "No",   value: "no" }
                        ],
                    def: "yes"
                }
            ]
        } );
    
        table = $('#stock_portfolios').DataTable( {
            ordering: true,
            order:          [[ 0, 'asc' ]],     
            
            dom: 'lBfrtip',
            "scrollY":      true,
            "scrollX":      true,
            
            ajax: {
                url: "../../" + EDITOR_DIR + "/controllers/dview-stock_portfolios.php",
                type: 'POST',
                data: function ( d ) {
                    d.userid = $('#passuserid').val();
                                    }
                },
            columns: [
                { data: "dm_portfolios.code" },
                { data: "dm_portfolios.name" },
                { data: "dm_portfolios.portfolio_type" },
                { data: "dm_portfolios.reporting_status" }
            ],
    /***********************************************************************
    * export buttons 
    ************************************************************************/       
            select: true,
            buttons: [
                { 
                    extend: "create", 
                    editor: editor, 
                    formButtons: [
                        'Create',
                        { text: 'Cancel', action: function () { this.close(); } }
                    ]
                },
                { 
                    extend: "edit",   
                    editor: editor, 
                    formButtons: [
                        'Edit',
                        { text: 'Cancel', action: function () { this.close(); } }
                    ]
                },
                {
                    extend: "selected",
                    text: 'Duplicate',
                    action: function ( e, dt, node, config ) {
                        // Start in edit mode, and then change to create
                        editor
                            .edit( table.rows( {selected: true} ).indexes(), {
                                title: 'Duplicate record',
                                buttons: 'Create from existing'
                            } )
                            .mode( 'create' );
                    }
                },          
                { 
                    extend: "remove", 
                    editor: editor, 
                    formButtons: [
                        'Delete',
                        { text: 'Cancel', action: function () { this.close(); } }
                    ]
                },
                        {
                    extend: 'collection',
                    text: 'Export',
                    buttons: [
                        'copy',
                        'excel',
                        'csv',
                        'pdf',
                        'print'
                    ]
                }
            ],
    /***********************************************************************
    * export buttons 
    ************************************************************************/               
    /***********************************************************************
    * lengthMenu 
    ************************************************************************/   
            iDisplayLength: 5,
            lengthMenu:     [ [1, 5, 10, 25, 50, 100, -1], [1, 5, 10, 25, 50, 100, "All"] ],
            language: {
               decimal:     ".",
               thousands:   ","
           },
    /***********************************************************************
    * lengthMenu 
    ************************************************************************/                   
    } );    
    } );    
        
    }(jQuery));</script>
    

    server script

    <?php
    
    /*
     * stock_portfolios.php
     */
     
    // DataTables PHP library
    include( "../lib/DataTables.php" );
     
    // Alias Editor classes so they are easy to use
    use
        DataTables\Editor,
        DataTables\Editor\Field,
        DataTables\Editor\Format,
        DataTables\Editor\Mjoin,
        DataTables\Editor\Options,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate,
        DataTables\Editor\ValidateOptions;
    
    $userid = $_POST['userid'];
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'dm_portfolios' )
        ->debug(true)
        ->fields(
            Field::inst( 'dm_portfolios.user_id' )
    // default the value of the userid to $userid        
                ->setValue( $userid ),            
            Field::inst( 'dm_portfolios.code' )
                    ->validator( Validate::notEmpty( ValidateOptions::inst()
                        ->message( 'A portfolio code is required' )
                ) ),
            Field::inst( 'dm_portfolios.name' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'A portfolio name is required' )
                ) ),
            Field::inst( 'dm_portfolios.portfolio_type' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'A portfolio type is required' )
                ) ),
            Field::inst( 'dm_portfolios.reporting_status' )
                ->validator( Validate::notEmpty( ValidateOptions::inst()
                    ->message( 'A reporting status is required' )
                ) )
                )
    
        
    ->where( function ( $q ) use ( $userid) {
    $q->where( 'user_id', $userid);
    } )
    ->debug(true)
    ->process( $_POST )
    ->json();
    
    

    any help much appreciated

    Thanks Colin

  • allanallan Posts: 63,523Questions: 1Answers: 10,473 Site admin
    Answer ✓

    Hi Colin,

    There isn't anything obvious in the above code that would cause a problem, but possibly I'm just missing it. Can you PM me the login details please?

    Allan

  • cpshartcpshart Posts: 246Questions: 49Answers: 5

    Hi Allan

    PM sent

    Thanks Colin

This discussion has been closed.