php object attribute with dot in name

前端 未结 5 461
借酒劲吻你
借酒劲吻你 2020-11-29 12:28

I have mysql table with collumns like \'operation.date\', \'operation.name\' and etc. After fetching that table data as object with $mysqli->fetch_object() i

相关标签:
5条回答
  • 2020-11-29 12:34

    The correct way of accessing properties with a dot should be :

    echo $object->{"operation.date"}
    
    0 讨论(0)
  • 2020-11-29 12:34

    Change the sql to return valid property names using the 'as' feature

    eg. select operation.date as date

    0 讨论(0)
  • 2020-11-29 12:36

    Specify aliases in your SQL query like SELECT column AS nameWithoutDots ...
    or access these properties with $object->{'operation.name'}
    or cast the object to array like this: $obj = (array)$obj; echo $obj['operation.name'].

    0 讨论(0)
  • 2020-11-29 12:51

    To access these attributes you need to wrap them with curly brackets:

    echo $object->{"operation.date"} //2010-12-15

    If you set an attribute this way the offending symbol gets removed, allowing you to access the attribute as echo $object->operationdate //2010-12-15

    0 讨论(0)
  • 2020-11-29 12:52

    You can get assoc array instead object by using $mysqli->fetch_assoc()

    0 讨论(0)
提交回复
热议问题