Jump to content

using $variable = function() { RETURN 'HELLO WORLD'; }


Monkuar

Recommended Posts

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.

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

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 364
Yeah, 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 -.-

 

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.

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?

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.