3

I created a set of helper functions to make my life easier when doing database operations in php. Essentially I pass the functions an stdClass Object that they then use to either perform an operation (delete, add, etc) or retrieve information. They seem to work as intended except for the helper function that is meant to delete database entries. What is frustrating to me is that works perfectly fine on my local machine running WAMP, but when I put it live it refuses to delete the database entries.

I think I've narrowed down the issue to a strange quirk I can't explain between the output of the stdClass Object between WAMP and my live site.

PHP:

<?php   
        session_start();
        require_once('dbconnect.php');
        require_once('dbhelpers.php');

        $cat = $_GET['cat'];
        $id = $_GET['id'];

        //remove row from table
        $a_remove = (object) array(
            "table" => "{$cat}",
            "columns" => (object) array(
                "`id`"
            ),
            "results" => (object) array(
                    "{$id}"
            ),
            "type" => (object) array(
                "i"
            )
        );
        removeRow($a_remove);
    ?>

Here is the output from the response on WAMP when I run a print_r on the $a_remove object:

stdClass Object
(
    [table] => subjects
    [columns] => stdClass Object
        (
            [0] => `id`
        )

    [results] => stdClass Object
        (
            [0] => 36
        )

    [type] => stdClass Object
        (
            [0] => i
        )
)

However when I do print_r on $a_remove on my live site, I get the following:

stdClass Object
(
[table] => subjects
[columns] => stdClass Object
    (
        [0] => `id`
    )

[results] => stdClass Object
    (
        [0] => 36
        [0] =>
    )

[type] => stdClass Object
    (
        [0] => i
    )
)

There is that strange additional index in the response for "result". Any ideas on what might be causing this?

Machavity
  • 30,841
  • 27
  • 92
  • 100
tomc
  • 417
  • 5
  • 17
  • 2
    Have you compared permissions? – wallyk Dec 30 '18 at 03:04
  • 3
    Same PHP versions? – Darren Dec 30 '18 at 03:14
  • @wallyk full permissions as far as I tell – tomc Dec 30 '18 at 03:26
  • @Darren WAMP php version: PHP 7.2.10 Web php version: PHP 7.0.32 – tomc Dec 30 '18 at 03:31
  • 2
    Version doesn't seem to matter. [No version seems to duplicate this](https://3v4l.org/Q10VO) – Machavity Dec 30 '18 at 03:33
  • 1
    I run wamp and did a few tests and output is expected, uploaded to my live server and can't seem to duplicate this. Does $_GET['id'] output as expected on live? – Second2None Dec 30 '18 at 03:35
  • 4
    To be perfectly honest, I think this is [another object coercion gotcha](https://stackoverflow.com/questions/1869812/casting-an-array-with-numeric-keys-as-an-object). In all seriousness, you should avoid `(object)[]` coercion at all costs because it can cause unexpected results like this – Machavity Dec 30 '18 at 03:39
  • @Second2None $_GET['id'] works as expected in both – tomc Dec 30 '18 at 03:42
  • @Machavity Interesting link! I'll try a workaround and see if that fixes the issue – tomc Dec 30 '18 at 03:45
  • 1
    If anyone ever encounters this issue, I seem to have fixed it by upgrading to php 7.2. – tomc Dec 30 '18 at 04:09

0 Answers0