0

help me understand.

The plug has not been updated for a long time _http://market.osclass.org/plugins/attributes/real-state-attributes_6

In the transition to PHP 5.4 is presented error.

Help, to deal with the error:

Warning: Illegal string offset 'pk_i_id' in C:\OpenServer\domains\oc-classrus.loc\oc-content\plugins\realestate_attributes\conf.php on line 109

Warning: Illegal string offset 's_name' in C:\OpenServer\domains\oc-classrus.loc\oc-content\plugins\realestate_attributes\conf.php on line 109

Warning: Illegal string offset 'pk_i_id' in C:\OpenServer\domains\oc-classrus.loc\oc-content\plugins\realestate_attributes\conf.php on line 109

Warning: Illegal string offset 's_name' in C:\OpenServer\domains\oc-classrus.loc\oc-content\plugins\realestate_attributes\conf.php on line 109

Line 109

$data[$locale['pk_c_code']] = array('pk_i_id' => $c['pk_i_id'], 's_name' => $c['s_name']);

File

<?php if (!defined('OC_ADMIN') || OC_ADMIN!==true) exit('Access is not allowed.');
/*
 *      OSCLass – software for creating and publishing online classified
 *                           advertising platforms
 *
 *                        Copyright (C) 2010 OSCLASS
 *
 *       This program is free software: you can redistribute it and/or
 *     modify it under the terms of the GNU Affero General Public License
 *     as published by the Free Software Foundation, either version 3 of
 *            the License, or (at your option) any later version.
 *
 *     This program is distributed in the hope that it will be useful, but
 *         WITHOUT ANY WARRANTY; without even the implied warranty of
 *        MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *             GNU Affero General Public License for more details.
 *
 *      You should have received a copy of the GNU Affero General Public
 * License along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
?>

<?php
if(Params::getParam('plugin_action')!='') {
    if(Params::getParam('plugin_action')=="type_delete") {
        if(Params::getParam('id')!="") {
            ModelRealEstate::newInstance()->deletePropertyType( Params::getParam('id') ) ;
        }
    } else if(Params::getParam('plugin_action')=="type_add") {
        $dataItem = array();
        $request = Params::getParamsAsArray();
        foreach ($request as $k => $v) {
            if (preg_match('|(.+?)#(.+)|', $k, $m)) {
                $dataItem[$m[1]][$m[2]] = $v;
            }
        }
        // insert locales
        $lastId = ModelRealEstate::newInstance()->getLastPropertyTypeId();
        $lastId = $lastId['pk_i_id'] + 1 ;
        foreach ($dataItem as $k => $_data) {
            ModelRealEstate::newInstance()->insertPropertyType($lastId, $k, $_data['property_type']);
        }
    } else if(Params::getParam('plugin_action')=="type_edit") {
        $property_type = Params::getParam('property_type');
        foreach($property_type as $k => $v) {
            foreach($v as $kj => $vj) {
                ModelRealEstate::newInstance()->replacePropertyType($k, $kj, $vj);
            }
        }
    }
}
?>

<div id="settings_form" style="border: 1px solid #ccc; background: #eee; ">
    <div style="padding: 20px;">
        <div style="float: left; width: 50%;">
            <fieldset>
                <legend><?php _e('Property types', 'realestate_attributes'); ?></legend>
                    <form name="propertys_form" id="propertys_form" action="<?php echo osc_admin_base_url(true);?>" method="GET" enctype="multipart/form-data" >
                    <input type="hidden" name="page" value="plugins" />
                    <input type="hidden" name="action" value="renderplugin" />
                    <input type="hidden" name="file" value="realestate_attributes/conf.php" />
                    <input type="hidden" name="section" value="types" />
                    <input type="hidden" name="plugin_action" value="type_edit" />
                <div class="tabber">
                <?php $locales = osc_get_locales();
                    $property_type = ModelRealEstate::newInstance()->getPropertyTypes(false) ;
                    $data = array();
                    foreach ($property_type as $c) {
                        $data[$c['fk_c_locale_code']][] = array('pk_i_id' => $c['pk_i_id'], 's_name' => $c['s_name']);
                    }
                    $default = current($data);
                    if(is_array($default)) {
                    foreach($default as $d) {
                        $data['new'][] = array('pk_i_id' => $d['pk_i_id'], 's_name' => '');
                    }}
                ?>
                    <?php foreach($locales as $locale) {?>
                        <div class="tabbertab">
                            <h2><?php echo $locale['s_name']; ?></h2>
                                <ul>
                                <?php
                                    if(count($data)>0) {
                                        foreach(isset($data[$locale['pk_c_code']])?$data[$locale['pk_c_code']]:$data['new'] as $property_type) { ?>
                                            <li><input name="property_type[<?php echo  $property_type['pk_i_id'];?>][<?php echo  $locale['pk_c_code'];?>]" id="<?php echo $property_type['pk_i_id'];?>" type="text" value="<?php echo  $property_type['s_name'];?>" /> <a href="<?php echo osc_admin_base_url(true);?>?page=plugins&action=renderplugin&file=realestate_attributes/conf.php?plugin_action=type_delete&id=<?php echo  $property_type['pk_i_id'];?>" ><button><?php _e('Delete', 'realestate_attributes'); ?></button></a> </li>
                                        <?php };
                                    }; ?>
                                </ul>
                        </div>
                        <?php }; ?>
                        <button type="submit"><?php _e('Edit', 'realestate_attributes'); ?></button>
                    </form>
                </div>
            </fieldset>
        </div>
        <div style="float: left; width: 50%;">
            <fieldset>
                <legend><?php _e('Add new property types', 'realestate_attributes'); ?></legend>
                <form name="propertys_form" id="propertys_form" action="<?php echo osc_admin_base_url(true); ?>" method="GET" enctype="multipart/form-data" >
                    <input type="hidden" name="page" value="plugins" />
                    <input type="hidden" name="action" value="renderplugin" />
                    <input type="hidden" name="file" value="realestate_attributes/conf.php" />
                    <input type="hidden" name="plugin_action" value="type_add" />

                    <div class="tabber">
                    <?php $locales = osc_get_locales();
                        $data = array();
                        foreach ($property_type as $c) {
                            $data[$locale['pk_c_code']] = array('pk_i_id' => $c['pk_i_id'], 's_name' => $c['s_name']);
                        }
                    ?>
                    <?php foreach($locales as $locale) {?>
                        <div class="tabbertab">
                            <h2><?php echo $locale['s_name']; ?></h2>
                            <input name="<?php echo  $locale['pk_c_code'];?>#property_type" id="property_type" type="text" value="" />
                        </div>
                    <?php }; ?>
                    </div>
                    <button type="submit" ><?php _e('Add new', 'realestate_attributes'); ?></button>
                </form>
            </fieldset>
        </div>
        <div style="clear: both;"></div>                                        
    </div>
</div>
<div id="settings_form" style="border: 1px solid #ccc; background: #eee; ">
    <div style="padding: 20px;">
        <div style="float: left; width: 100%;">
            <fieldset style="border: 1px solid #ff0000;">
                <legend><?php _e('Warning', 'realestate_attributes'); ?></legend>
                <p>
                    <?php _e('Deleting property types may end in errors. Some of those property types could be attached to some actual items', 'realestate_attributes') ; ?>.
                </p>
            </fieldset>
        </div>
        <div style="clear: both;"></div>
    </div>
</div>
Machavity
  • 30,841
  • 27
  • 92
  • 100
Airclaim
  • 1
  • 1
  • `$c['s_name']` does not exist. also none of the other fields mentioned exist. Simples – RiggsFolly Mar 17 '16 at 13:28
  • You might have been getting these warnings all along, and the change is that PHP is now configured to show them rather than suppressing them. Check your server log history to confirm this. – Simba Mar 17 '16 at 13:31
  • @simba So you are suggesting that the code was always badly written, and should be fixed now, Right? I hope you are not suggesting turning error reporting off and keeping the bad code. – RiggsFolly Mar 17 '16 at 13:32
  • 1
    @RiggsFolly - I'm not suggesting that at all. I'm simply pointing out that it may not actually be the change in PHP *version* that's triggered it to start appearing; rather it may be a change in the PHP *config* that went along with the version upgrade. The point is that if you start with the assumption that it's an issue with PHP 5.4 when it isn't, it would make it harder to track down the actual root issue. I am just challenging that assumption. – Simba Mar 17 '16 at 13:38
  • If I use php 5.3, there is no problem. The error appears when the 5.4, 5.5, 5.6. I have to VPS version of php 5.4. Change of the version is not possible for many reasons. – Airclaim Mar 18 '16 at 08:04

1 Answers1

1

Where you have $c['pk_i_id'] the thought is clearly that $c will be an hash table (array) with an index named pk_i_id. However, PHP is telling you it's actually a string and thinks you're trying to do $c[7] to get a specific character from the string — and of course pk_i_id is not a number.

So what is $c? Do a var_dump($c); and see what's in there. Is it an error message instead of a property? What's changed?

It may be that the object you're getting here is no good anymore:

$property_type = ModelRealEstate::newInstance()->getPropertyTypes(false) ;

Check what that whole array looks like (with another var_dump())

There's no obvious problem in just the code you posted so I can't suggest any one particular thing to change, but whatever the problem is lies somewhere in that direction.

VoteyDisciple
  • 37,319
  • 5
  • 97
  • 97