Phalanger behaves unexpectedly with magic constructor

Discussion about the open-source Phalanger [?] project.

Phalanger behaves unexpectedly with magic constructor

Postby lesmocasanova » July 5th, 2014, 5:15 am

I couldn't come up with a better name for this. I'm trying to port an existing PHP application to Phalanger, so far I've been able to connect to my SQL Azure Database (took me several hours to figure out, might as well post about it in the examples board later) but now I'm facing an interesting issue here that I think is a bug in Phalanger's parser or compiler.

My application is built with CodeIgniter framework and using Wanwizard's DataMapper ORM to abstract the data layer. The problem is that DataMapper's core class' constructor is built to be backwards compatible with PHP 4 (check the problematic source), so it uses a constructor pattern like this:
Code: Select all
class InfiniteLoop {
   public function __construct($param) {
      $this -> InfiniteLoop($param);
   }

   public function InfiniteLoop($param) {
      echo 'We did it!';
   }
}


Phalanger crashes with a Stack Overflow exception because apparently calling the $this->InfiniteLoop method makes Phalanger call __construct method again... creating the awful infinite loop and eventually throwing the Stack Overflow exception.

Obviously the workaround is to simply remove __construct or refactor it to something like this:
Code: Select all
class InfiniteLoop {
   public function __construct($param) {
      echo 'We did it!';
   }
}


I can do that, but it's obviously not a good idea to mess with third party libraries that will get updated eventually. It's bad practice. Also, I believe there's still a few scripts around that try to be backwards compatible with PHP 4 (insane I think, but still :lol: ) that could benefit from fixing this little bug.

I'm using Phalanger 3. I don't know if it's already fixed or marked as "won't fix" in Phalanger 4.
User avatar
lesmocasanova
 
Posts: 11
Joined: October 16th, 2013, 8:26 pm
Location: Mexico

Re: Phalanger behaves unexpectedly with magic constructor

Postby Jakub Misek » July 5th, 2014, 3:11 pm

Hi,

This is an interesting bug, could you please file it at https://github.com/DEVSENSE/Phalanger/issues

Thanks,
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague

Re: Phalanger behaves unexpectedly with magic constructor

Postby lesmocasanova » July 5th, 2014, 8:33 pm

Good! I thought about filing the issue, but seeing as Phalanger's source is hosted in Codeplex and Github I didn't know which one is actually being maintained.

I've created a new issue on Github. See you next time!

P.S.: I'm starting to become Devsense's honorary bug-tester, uh? :lol:
User avatar
lesmocasanova
 
Posts: 11
Joined: October 16th, 2013, 8:26 pm
Location: Mexico

Re: Phalanger behaves unexpectedly with magic constructor

Postby Jakub Misek » July 7th, 2014, 5:27 pm

Thanks :-)
Jakub Misek │ DEVSENSE s.r.o. | @misekjakubjakub@devsense.com
User avatar
Jakub Misek
 
Posts: 2092
Joined: January 4th, 2012, 2:42 pm
Location: Prague


Return to Phalanger project

Who is online

Users browsing this forum: No registered users and 21 guests

cron

User Control Panel

Login

Who is online

In total there are 21 users online :: 0 registered, 0 hidden and 21 guests (based on users active over the past 5 minutes)
Most users ever online was 256 on March 28th, 2024, 9:42 am

Users browsing this forum: No registered users and 21 guests