ionCube Logo
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


 
Post new topic   Reply to topic    ionCube Forum Index -> Programming

foreach($this) problem

Author Message
eithe



Joined: 14 Mar 2012
Posts: 3

PostPosted: Wed Mar 14, 2012 5:43 pm    Post subject: foreach($this) problem Reply with quote

Hi there,

While implementing a website using ioncube we've encountered a segmentation (11) fault, which, as I've managed to track it, was cause by one of the classes. Oddly enough, when substituting the class with unencrypted version of it everything was working fine. As the entire class had to be encrypted I've tracked which line of code was causing it, and here I am.

When iterating through $this, as

Code:
foreach($this as $key => $value)
unset($this->{$key});


a segmentation fault occurs.

Substituting such line with one that does the very same thing:

Code:
$keys = array_keys(get_object_vars($this));
foreach($keys as $key)
if (!empty($key))
unset($this->{$key});


solves the problem. (Another oddity - there needs to be an if (!empty($key)) check - even though there are no empty keys on that object! How can there be?)

I've tried to replicate the problem without using our classes, in this code:

Code:
<?php

class A
{
    public $a = 'a';
   
    public function delete()
    {
        foreach($this as $key => $value)
            unset($this->{$key});
    }
}

$a = new A();
$a->delete();
var_dump($a);

?>


as such this will return, correctly:

Code:
object(A)#1 (0) { }


However, the same, encrypted code will yield NULL, which I assume causes the domino effect.

PHP version: 5.2.14
ioncube loader version: 3.1.28
ioncube encoder is, I think, version: 6.5
OS: Red Hat 4.1.2

If this is error has been solved somewhere, I'll appreciate the link, though I've searched the forum, but couldn't find anything similar.

If required I can provide further information - cheers for any help!

--

edit: fixed an inconsistency in the example
Back to top
View user's profile Send private message
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2771

PostPosted: Fri Mar 16, 2012 11:08 am    Post subject: Reply with quote

Hi

Thanks for the example. The first observation is that you do have a very old Loader from the 3.1 series, which was followed by the 3.3 series and now series 4 Loaders. We tried using the 6.5 Encoder and version 7 Encoder with a version 3.3.20 Loader and also the current Loader, and couldn't reproduce. The code also works with our upcoming Loader for PHP 5.4. So using an updated Loader should resolve for you.
_________________
Community Admin
Back to top
View user's profile Send private message
eithe



Joined: 14 Mar 2012
Posts: 3

PostPosted: Mon Mar 19, 2012 4:23 pm    Post subject: Reply with quote

Cheers Nick - that's a response I was hoping for. Sadly, I'm not in charge of hosting, but I can pass the word along Smile
Back to top
View user's profile Send private message
eithe



Joined: 14 Mar 2012
Posts: 3

PostPosted: Tue Mar 27, 2012 4:23 pm    Post subject: ivirmfo chophysical Reply with quote

Hi again!

The loader version has been updated to new one (4.0) and it's still producing same results, even with this example. I can provide an encoded file if you need it (though don't know if it will be any helpful).

edit: I've checked the encoded output on two servers - our clients and ours (both output NULL). The loader version differ though, but we want to definitely have it working on clients server Smile
Back to top
View user's profile Send private message
liaison
ionCube Support


Joined: 16 Dec 2004
Posts: 2771

PostPosted: Sat Mar 31, 2012 7:11 pm    Post subject: Cannot reproduce Reply with quote

I can't reproduce any problem with the code that you posted. It works as expected both with the previous Encoder 6.5.16 and our latest series, and running on PHP 5.2.0, 5.2.14 that you're using, and PHP 5.3. You might check that you're using the highest update to 6.5, and you can update for free in the members' area if not.

So check carefully what you're doing, make sure that you really are using a recent Loader, and if you still have a problem then please create a support ticket at http://support.ioncube.com with sample code, and we'll see again if we can reproduce.
_________________
Community Admin
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    ionCube Forum Index -> Programming All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum