Yii Framework Forum: Eval usage in Yii - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Eval usage in Yii eval = evil! Rate Topic: ***** 1 Votes

#1 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 11 February 2010 - 10:39 AM

Hey all, I understand why Yii uses eval() 11 times throughout it's PHP code, but is it truly necessary?

The point is that eval is inherently slower (and if used improperly, unsafe), but more importantly, many companies will likely start to look at PHP + HipHop (aka hphp, a solution from Facebook to compile PHP code as C++ extensions, for speed). HipHop removes support for eval(), which means that by default, Yii cannot be considered as a framework for massive applications such as Facebook, etc, where performance is a major concern.

It would be nice to see Yii taken seriously in that respect.

Cheers

-Jon
Need live Yii support? - Join the #yii IRC channel on Freenode!
0

#2 User is offline   notzippy 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 201
  • Joined: 06-October 08

Posted 11 February 2010 - 10:58 AM

I support this idea also.
Even if I need to modify the way my business rules are written.

nz
0

#3 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 11 February 2010 - 10:59 AM

It is not scientific to draw the conclusion that having eval() in a library would necessarily mean the library is poor in performance. If so, would you consider PHP itself is slow since its numerous 3rd party libraries contains thousands of eval()'s?

Also, hiphop removing support for eval() doesn't mean it can't run PHP code with eval() code. In fact, I believe hiphop also doesn't support other dynamic language features of PHP.

Having said the above, among these 11 eval() in Yii, none of them appears in the core framework execution path. In fact, some of these eval()'s appear in console commands where performance is not a concern, while some others appear in optional features that you are free not to use them.

In order to improve performance, it is very important to make sure you only load/execute code that are necessary for a particular request (the so-called on-demand loading or lazy execution). It is because of this reason that Yii is much faster than other frameworks.
0

#4 User is offline   qiang 

  • Yii Project Lead
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,907
  • Joined: 04-October 08
  • Location:DC, USA

Posted 11 February 2010 - 11:02 AM

HipHop is not a panacea to cure performance problem. Before you should resort to using HipHop, there are many other places that you should dig into to improve performance, such as optimizing your SQL queries, using caching techniques, reducing unnecessarily executed code, etc.
0

#5 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 11 February 2010 - 11:12 AM

View Postqiang, on 11 February 2010 - 11:02 AM, said:

HipHop is not a panacea to cure performance problem. Before you should resort to using HipHop, there are many other places that you should dig into to improve performance, such as optimizing your SQL queries, using caching techniques, reducing unnecessarily executed code, etc.


Agreed, and I think Yii is very optimal in that regard, it just would be nice to reduce the evals if they aren't 100% necessary in each relevant section of code.

BTW, qiang, why do core developers not spend any time in IRC? Small group of people in there, but would be nice to have a core dev participate :-)
Another IRC user was saying yesterday that 1 or 2 other core devs used to be in IRC pretty often, now they're never there. It's a shame
Need live Yii support? - Join the #yii IRC channel on Freenode!
0

#6 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,225
  • Joined: 17-January 09
  • Location:Russia

Posted 11 February 2010 - 12:05 PM

HipHop is not needed if you are not Facebook. At least it's really hard to optimize everything (algorithms, DB etc.) so PHP code itself will be a bottleneck.

Why using IRC? There is a forum that is read and answered by core team.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#7 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 11 February 2010 - 07:41 PM

View Postsamdark, on 11 February 2010 - 12:05 PM, said:

HipHop is not needed if you are not Facebook. At least it's really hard to optimize everything (algorithms, DB etc.) so PHP code itself will be a bottleneck.

Why using IRC? There is a forum that is read and answered by core team.


IRC gets live discussions going, which is nice to have as an option w/ experienced users/devs
Need live Yii support? - Join the #yii IRC channel on Freenode!
0

#8 User is offline   Junior - df9 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 416
  • Joined: 24-May 09
  • Location:Brazil

Posted 11 February 2010 - 07:57 PM

PHP is PHP....C++ is C++...personally, I don't like the idea of turning PHP into C++

and I also think that Yii shouldn't be made to fit the needs of HipHop, but instead, HipHop should fix its code to make eval() be converted in C++ sentences, once this is the major purpose of the tool (convert PHP into C++)...

regards!!

:)
______________________________________
Junior
df9.com.br
Linux Registered User #364954
GNU/Linux: together we're ready!
1

#9 User is offline   Mike 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 3,017
  • Joined: 06-October 08
  • Location:Upper Palatinate

Posted 12 February 2010 - 03:39 AM

View Postintel352, on 11 February 2010 - 07:41 PM, said:

IRC gets live discussions going, which is nice to have as an option w/ experienced users/devs


Keep in mind: Most here got a job and only very limited time. I prefer that developers spend time on coding instead of chatting in IRC. ;)
0

#10 User is offline   scythah 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 44
  • Joined: 20-April 09

Posted 12 February 2010 - 04:53 AM

View PostMike, on 12 February 2010 - 03:39 AM, said:

Keep in mind: Most here got a job and only very limited time. I prefer that developers spend time on coding instead of chatting in IRC. ;)

I agree. I think being in IRC would either mean that nothing would get done on the framework (as all of the time would be spent answering (generally) straight-forward questions), or the dev team would be on IRC, but would ignore everything there anyway since it's too much of a distraction.
0

#11 User is offline   Sander 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 169
  • Joined: 03-November 09
  • Location:Amsterdam, Netherlands

Posted 12 February 2010 - 04:59 AM

The eval() issue is a bit bigger than just HipHop, though. eval() allows for great flexibility for instance with RBAC and its business rules, but is potentially unsafe whenever any user input is evaluated therein. In this particular case, I don't really see why these business rules cant be handled for instance by specifying a callback to a boolean function, which handles the logic. Since PHP5.3 and its anonymous functions, these can even be created on the fly for maximum flexibility (though that probably wouldn't be necessary 99% of the time). A side benefit of this would be easier debugging, since eval()d code in RBAC is ran with an error suppressor (@), so it's not obvious when for instance there's a typo in a business rule.
0

#12 User is offline   Sergey Kuznetsov 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 93
  • Joined: 16-February 09
  • Location:Russia, Saratov

Posted 12 February 2010 - 05:19 AM

Hey, guys!

Yii is open source. Also Yii very-very-very flexible framework (the most flexible I've ever seen before).

If you need to compile your Yii project into "C++" code via HipHop just take the framework's source code, change it (or make changes to your's application - replace needed classes and go on!), and make a fork (if you want to share your code with community).
http://summercode.com - Just an info page.
http://wiki.summercode.com/ - Many articles and tips about programming, patterns, language, SCMs, server administration and other stuff.
http://careers.stack...ergey-kuznetsov - CV page.
0

#13 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,225
  • Joined: 17-January 09
  • Location:Russia

Posted 12 February 2010 - 05:21 AM

RBAC bizRules could be stored in DB so eval is necessary here.
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#14 User is offline   intel352 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 196
  • Joined: 05-February 10
  • Location:Southport, NC

Posted 12 February 2010 - 09:06 PM

View Postscoob.junior, on 11 February 2010 - 07:57 PM, said:

PHP is PHP....C++ is C++...personally, I don't like the idea of turning PHP into C++

and I also think that Yii shouldn't be made to fit the needs of HipHop, but instead, HipHop should fix its code to make eval() be converted in C++ sentences, once this is the major purpose of the tool (convert PHP into C++)...

regards!!

:)


The point is to convert it for high-level performance, not for ongoing maintenance. You would still develop your code in PHP, just compile for production use. And a possible application for this (in addition to higher performance results) is to also be able to compile a web application for commercial distribution (possibly).

The developers of HipHop feel that eval is unneeded (and reduces performance), and afaik they don't intend to add eval back in.
Need live Yii support? - Join the #yii IRC channel on Freenode!
0

#15 User is offline   mech7 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 220
  • Joined: 26-March 09

Posted 14 July 2010 - 11:59 PM

View Postsamdark, on 12 February 2010 - 05:21 AM, said:

RBAC bizRules could be stored in DB so eval is necessary here.


True but the way they are used in the examples are not that usefull... Add a guest or member account / small if statement for user id..

I understand that it's easier for an admin to assign a edit own rule, but for the programmer much harder to track back what's happening with the "invisible code".

Also CGridView depends on eval but do we really want/need php expressions evalled to modify some date column :P

I think the biggest problem is not that it is slow, but can become hard to read, hard to debug and when not very carefully can lead to some dangerous situations too :) And I guess most programmers seem to agree eval == evil :P
0

#16 User is offline   samdark 

  • Having fun
  • Yii
  • Group: Yii Dev Team
  • Posts: 5,225
  • Joined: 17-January 09
  • Location:Russia

Posted 15 July 2010 - 05:03 AM

Well, I agree that if we can avoid eval without too much cost we should. Proposals are always welcome ;)
Yii 2.0 Development Cookbook

Enjoying Yii? Star us at github

Support me so I can work more on Yii: https://www.patreon.com/samdark
0

#17 User is offline   le_top 

  • Advanced Member
  • PipPipPip
  • Yii
  • Group: Members
  • Posts: 460
  • Joined: 08-June 10
  • Location:France (Ile-de-France/Val d'Oise)

Posted 25 February 2012 - 09:40 AM

For those that want to dig further into hiphop. PHP begin similar in several ways to Perl, some anwsers may be in what has been done for perl.

In perl, B::CC seems to be capable of handling evals because there is an option explicitally referring to it:
http://search.cpan.o....42/lib/B/CC.pm

"-uPacknameForce apparently unused subs from package Packname to be compiled. This allows programs to use eval "foo()" even when sub foo is never seen to be used at compile time. "


And a discussion of generators for perl here:
http://oreilly.com/c...ml#AUTOID-22694
0

#18 User is offline   jpm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 26
  • Joined: 17-April 11
  • Location:Austin TX

Posted 25 February 2012 - 04:39 PM

If you think you're going to need a tool like HipHop you should probably re-asses and choose a language more suited to your task.
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users