New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"PHP warning: Illegal offset type" when saving object with compound primary key #129

kristk opened this Issue Jan 15, 2018 · 1 comment


None yet
2 participants
Copy link

kristk commented Jan 15, 2018

I get this PHP warning when i try to save an object that uses a compound primary key:
(ERROR @ .../core/xpdo/om/xpdoobject.class.php : 1478) PHP warning: Illegal offset type

The warning is produced in modx 2.6.0 running om PHP 7.1.13.

I have a minimal table that uses this schema:

<?xml version="1.0" encoding="UTF-8"?>
<model package="trippeln" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
  <object class="NumberSeq" table="trippeln_number_seq" extends="xPDOObject">
    <field key="level" dbtype="enum" precision="'G','S','B'" phptype="string" null="false" index="pk" />
    <field key="number" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" index="pk"  generated="native" />

    <index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
      <column key="level" length="" collation="A" null="false" />
      <column key="number" length="" collation="A" null="false" />

Here is an image showing the table structure in phpMyAdmin:

The modx snippet code that produces the warning is:

$number = $modx->newObject('NumberSeq');
$number->fromArray(array('level' => 'B', 'number' => NULL,), '', true);

The code line that is referenced ( uses the result from getPK() as an array index but since getPK() in this case returns an array that produces the warning. The save method should be changed so that it can handle compund keys as well but I don't know the best way to do it.

My code works in that way that the object is saved to the database correctly.

@opengeek opengeek self-assigned this Jan 15, 2018

@opengeek opengeek added the bug label Jan 15, 2018


This comment has been minimized.

Copy link

opengeek commented Jan 15, 2018

Thanks for the issue. xPDO can handle compound keys, but the problem here is I never anticipated a case where a compound key would include an auto_increment value. I'll have to refactor the code there to handle this kind of situation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment