Hi everyone,
At last I've decided to stop writing procedural PHP code and move to OO PHP coding. As it seems I'm pretty late to OO PHP party, so can someone provide me few links to get started with.
For now I'm following these few links to see how things works in oo
http://code.tutsplus.com/tutorials/object-oriented-php-for-beginners--net-12762
http://stackoverflow.com/a/20681770
Welcome to the latecomers party! :dancers:
I tend to prefer the "learn-by-doing" approach, so I have not read much...
But, in the last couple of days I was trying to get a hold of dependency injection and all the buzz and I found this blog:
http://misko.hevery.com/2008/10/21/dependency-injection-myth-reference-passing/
It speaks Java, but is not that different LOL
There are some interesting articles I think, at least I think I got a better idea of what is going on. :P
Thanks :D
Well I also try to take the same approach for most of the instances, but this time I'm thinking of making an exception by doing some sort of crash course
Surely going to read it out
Hmm... not sure about tutorials. I would look at frameworks like Symfony or ZF. You'll learn a lot about separation of concerns, dependency injection, etc. Creating a good, clean class is an art. Although thinking of things as objects is the basis for OOP, writing good code is how you keep from just making it procedural with namespaces.
Well I've started on OOP, and it seems to be a big task for sure, but this time I'm going to nail it. For some reason 'spl_autoload_register' is giving me all kinds of odd className, but not the ones I require.
Joker is going for a small nap (12hrs atleast :P), here's the
code (https://github.com/siddhartha-gupta/SMF-Likes/tree/v_2.0) I was playing with :-[ .
As soon as I clicked post I realized why you are using static functions. Yuck, that's a huge issue with the event system. Sorry, looks like you need to do that for now.
Reading it.. seems interesting
Okzz, singleton seems promising, working on globals as well
Actually its one of my SMF's mod on which I'm playing/trying out OOP things. As Elk is already in object oriented mode, so I thought of learning on SMF2, as there is nearly zero support for OOP as of now. With Elk I've seen/learnt few things already about OOP.
Its readme copy past, joker is lazyyyyyyy :D
Thanks for all the advices and suggestion, back to codes
@groundup, I tried passing global vars in 'LikePosts::getInstance' by reference, but '$context' etc doesn't seem to have update value. I mean, these global vars are set up pretty early in class, but '$context, $settings' seems to be filled up at a later stage. Due to which when the code tries to access the values from these vars/arrays it fails.
Can you provide me a small snippet about passing the global vars to a class instance, and class can have the update value of the variable
The way the hook system is now, you have to keep it the way you have it. You can't instantiate an object. So, you have to use static methods. Singleton is an anti-pattern which should be avoided.