Monkuar Posted January 22, 2015 Share Posted January 22, 2015 (edited) This is object programming right? Is there a performance issue with this? for example: $notfications = ( blah blah ) ? : ''; then if ($notificatiosn != blabla){ echo 'hey'; } or.... $notifications = function(){ do my stuff here then return 'hey'; } Which way is faster or slower? Reason I Ask this is because I've been doing some object orientated programming in javascript, and didn't know you could do it in php. I'd rather do the objective way so I don't have to use so many freaking variables above the regular way, lol. Edited January 22, 2015 by Monkuar Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 22, 2015 Share Posted January 22, 2015 No that has nothing to do with OOP. Your first example is using the ternary comparison operator, which is just a short way if writing if/else statements (javascript has that as well). Your 2nd code block is called an anonymous function. 1 Quote Link to comment Share on other sites More sharing options...
Monkuar Posted January 22, 2015 Author Share Posted January 22, 2015 Also, when using this I get: Catchable fatal error: Object of class Closure could not be converted to string in C:\WT-NMP\WWW\header.php on line 364Yeah, no idea. Never seen this error. I have a feeling I can only use the object orientated functions inside a Class right? If so, nevermind my question -.- Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted January 22, 2015 Solution Share Posted January 22, 2015 This is object programming right? Nope The first block of code uses ternary operator (aka inline if/else statement) and a if statement. Second block of code uses an anonymous function. None of which features object oriented programming. Which way is faster or slower? Why would that matter? You will not be able to notices the differences between the two. Reason I Ask this is because I've been doing some object orientated programming in javascript, and didn't know you could do it in php. object orientated programming in javascript is not the same as object orientated programming in PHP. 1 Quote Link to comment Share on other sites More sharing options...
Monkuar Posted January 22, 2015 Author Share Posted January 22, 2015 No that has nothing to do with OOP. Your first example is using the ternary comparison operator, which is just a short way if writing if/else statements (javascript has that as well). Your 2nd code block is called an anonymous function. Yeah, but Anonymous functions exist inside objective orientated programming right? Quote Link to comment Share on other sites More sharing options...
CroNiX Posted January 22, 2015 Share Posted January 22, 2015 Yeah, but Anonymous functions exist inside objective orientated programming right? Yes, but so do ternary operators and most other PHP commands. Just because they are used within a class (which is OOP) doens't make them "oop". Echo works in a class too, but doesn't mean it's "oop". Creating and using classes is OOP. The class itself. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.