Forums

PHP education

I’m trying to learn more about PHP and I’m at the point where it seems I’m not really getting anywhere. I feel like I’m learning the wrong way (using Kirby which I have been instructed to “throw it as far overboard as possible”).

What kind of projects should I build that would be efficient to learn? Some have recommended that I create a minimalist project.

Should I jump into OO PHP, templating? Sorry if I’m not making sense. Some have also recommended the PHP docs but I’ve never been able to learn through there. I’ve only used it as a resource to double check global variables or see if I’m doing something correctly. I’d prefer to learn from a resource similar to how MDN does it for html in which it basically tells you when to use certain elements. I’m not sure if that really applies to how PHP works or if there are such resources.

On the Stack Overflow chat, one person recommend this project but if you view the solution for PHP, I’m not even at that level to create functions, etc.

Kirby which I have been instructed to “throw it as far overboard as possible”

Out of curiosity, why? I’ll admit that it’s not the best stuff I’ve seen (especially the older version), but nothing really struck me as “wrong.” I haven’t used/ investigated it in depth, though.

I’m not even at that level to create functions, etc.

If you’re not comfortable with them, functions are definitely the next thing to learn. You have a task: put arguments in, return a result.

I’ll second learning object-oriented programming. I don’t like java, though (personal preference). While javascript and php have different rules, js is pretty good at teaching you how to think in object-oriented terms.

About a specific project…

I would recommend against tying yourself to someone else’s project. You’d be limiting yourself not only to their approach and abilities, but to the specific goals of the project (including delivery: i.e., if you discover a need to scrap what you’ve built and start over, you don’t want a lot of pressure not to).

If you want to learn about OOP, maybe you could start by making objects to handle the HTTP Request and Response. Easy to model, think up methods for, useful for future projects. And a response object could lead to a way to handle templates.

About a specific project: there’s a person trying to set up his own site/forum kind of thing on this forum, maybe you could do the same thing, or even join and help him? – @soronbe

I have been following that thread since it began but I just don’t have the time to be involved in a project where someone might be counting on me. My schedule is soon to get whacky now that school is about to begin.

Out of curiosity, why? I’ll admit that it’s not the best stuff I’ve seen (especially the older version), but nothing really struck me as “wrong.” I haven’t used/ investigated it in depth, though. – @traq

Apparently because it “uses static calls everywhere” and that is generally bad practice according to the person I spoke to on the PHP chat over at Stack Overflow. He also suggested that I not begin learning templating at this stage as it might be a little difficult if I don’t know basic functions and classes.

I’ll second learning object-oriented programming. I don’t like java, though (personal preference). While javascript and php have different rules, js is pretty good at teaching you how to think in object-oriented terms. – @traq

Is it fundamental that I choose a different language just to grasp OOP in PHP? It’s not that I don’t comprehend OOP because I don’t think I’ve ever really took the time to read up on it.

I would recommend against tying yourself to someone else’s project. You’d be limiting yourself not only to their approach and abilities, but to the specific goals of the project (including delivery: i.e., if you discover a need to scrap what you’ve built and start over, you don’t want a lot of pressure not to). – @traq

Exactly! I wish I had time to contribute to the project suggested above. I really do. But my schedule would not allow me to and I wouldn’t want to disappoint or frustrate someone because of that.

Is it fundamental that I choose a different language just to grasp OOP in PHP?

No, not really. I wish I had a good resource for you… I had an “ah-ha!” moment with OOP, but I’m not sure I could point out specifically what led to it.

I think what confuses me in regards to functions is the whole public/private thing.

Functions don’t have public/private; that’s objects.

As for when to use public vs. private, it all comes down to how the property/method is used. Public methods are those that you intend to use in your code; private methods are only meant to be used internally by the object itself.

Don’t worry too much about it in the short term. It is an important concept, but you won’t “ruin” things by making everything public to start and going back to it later, once you understand what’s going on more clearly.

I am not saying OOP/PHP is terrible, but it is far from the ideal first OOP language. A lot of people that were taught OOP solely by PHP seem to think a class is merely a container for methods and (if lucky) some attributes.

Well, I’d argue that that —like most of the language— is an issue of how people use it, not how it actually works.

Ah. Yeah, in places he’s just treating objects as a way of “namespacing” (grouping) functions together. As Soronbe pointed out, that’s not really what OOP is for. An object represents a specific thing, and its methods represent what it can do/ what you can do to it.

Ok. Perhaps that’s where my confusion is, in regards to functions since I see a lot of code that looks like this:

public function something() {
....
}

I think I’m just over-complicating it.

Ah. Yeah, in places he’s just treating objects as a way of “namespacing” (grouping) functions together. As Soronbe pointed out, that’s not really what OOP is for. An object represents a specific thing, and its methods represent what it can do/ what you can do to it.

We had a private conversation in which he relayed to make my own experiences rather than listen to what other people object to. Which is absolutely great advice but when it comes to programming or development in general, even though there are multiple ways to build the same thing, there is also room to go about it the wrong way, specifically on how the language was designed to do certain things. I hope that makes sense.

We had a private conversation in which he relayed to make my own experiences rather than listen to what other people object to.

Well, yes, but things are also designed and built with specific purposes in mind. Using a class as a “name” wrapper for a bunch of loosely-related methods might work —in the sense that it accomplishes that goal and doesn’t really break anything in doing so— but there is no advantage in using a class this way.