Jump to content

Archived

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

Korferer

Hello from... Bristol, UK

Recommended Posts

Hi.

 

 

 

I'm not exactly new to PHP but I am brand new to this community. I have been PHP aware for about 5 years but in all that time the amount of coding I have actually done has been rather pathetic. I work for a company that is quite... insular, and secluded (their choice, not mine) from the wider developer community. As a result I only discovered PHP Frameworks about a year ago and feel quite behind the times.

 

 

 

I am used to writing procedural PHP and not much else. I am here to hopefully broaden my horizons and get a better understanding of Frameworks, OOP, SQLi or PDO or database "unspecific" applications. 

 

 

 

When I first discovered PHP Frameworks about a year ago, my friend suggested I get started using CodeIgniter (that seems to be a lot of newbies' first choice!). I loved it, but after reading various rantings and ravings on the internet I decided that I should probably move on to something more "professional". That's when I came up against SF2 and almost cried myself to sleep every night. It made no sense to me. It still makes no sense to me. I gave up.

 

 

 

After that I tried Laravel but couldn't even get going thanks to something called "Composer" which I still don't understand. I thought to myself, "I don't want to learn about dependencies at this stage, I just want to code". I gave up.

 

 

 

Then another friend suggested I use PHP Slim. Another Framework. I tried to work with it but it seemed heavily dependant on knowing OOP, and I didn't have the first clue what I was doing. I gave up (are you sensing a pattern here?)

 

 

 

So after that, I decided to try and learn the basics of OOP and how/why it was better than procedural and I have to say - I don't think it is. And I kind of hate it. I find it really confusing and not one person I have asked is able to tell me why OOP is better than procedural. They say "it just is".

 

 

 

Sigh.... Then I decided to join PHP Freaks so I could vent my frustrations!

 

 

 

Share this post


Link to post
Share on other sites

Welcome to the community.

 

Don't feel like your on your own when it comes to the way you have progressed. Usually a developer will only progress as far as the company they work for requires them to (unless you are using your free time to extend your knowledge). i.e. If your company is churning out websites that don't need masses of programming code then why would the company need a developer to invest their time into learning a framework. It's good that you have decided to broaden your skills by learning about frameworks and OOP on your own. You will certainly get the help you need here.

 

I would certainly not shy away from learning frameworks. I think it it good to have worked with 2 frameworks to get an idea of the pros and cons of each. You will find that they will overlap in terms of how code is laid out in a lot of parts. You already have CodeIgniter under your belt, and that is great. It has one of the best sets of documentation out of all of the frameworks and that is important. Forget about what the critics say, at the end of the day you are learning and you can make your own mind up. If you're looking for the next framework to learn that is the next step up from CI then I would strongly recommend Yii (not version 2 yet) http://www.yiiframework.com/ It has good documentation, a strong community, and lots of tutorials on youtube, etc. I moved onto Yii from using CodeIgniter for quite a few projects and haven't looked back. I would also get a copy of the following eBook to read through http://yii.larryullman.com/

Share this post


Link to post
Share on other sites

On another note, to answer your question

 

 

So after that, I decided to try and learn the basics of OOP and how/why it was better than procedural and I have to say - I don't think it is. And I kind of hate it. I find it really confusing and not one person I have asked is able to tell me why OOP is better than procedural. They say "it just is".

 

OOP and Procedural Programming are terms used to describe code structure. There is no, "one is better than the other". Each is suited to particular scenarios. Procedural code basically refers to line by line structure meaning you write code from the top to the bottom in the order it is to be executed i.e

 

1. check if a form has been submitted

2. validate the data

3. display any errors

4. if no errors save the data to the database and redirect the user

5. display the form

 

OOP refers to a system where all the component parts are separated into what are known as objects i.e. users, database, forms, apples, oranges, pears, etc. Objects can interact with each other i.e. A user object can use a database object that will allow it to generate a fruit object that can be an apple, an, orange or a pear. If you were to try and write this sort of behavior in a procedural style you may think ah, easy. However, what if I want to change the type of database I am using, what if I want to add a new type of fruit, or add extra types of forms. You are going to have to add to or edit many lines of code to achieve this and may end up forgetting to alter one line in a certain page of your site breaking the whole application. Procedural code can quickly become spaghetti code that is difficult to read an debug. This is where OOP would be better suited.

 

I use both types of programming every day. If I am churning out a small website with a contact form, a gallery, maybe a blog. I would write the majority of it procedurally. I'm going to use a few objects here and there i.e using the mysqli object for connecting to and running database queries. There is no need for OOP in this scenario, procedural is the better choice. If I have the task of writing an e-commerce application that may have a multi user CMS that requires role based access controls, many types of forms and lots of different types of data to validate, and include an API for third party apps to connect into and extract data. I am certainly not going to write this in a line by line Procedural style, especially if there will be more than one developer working on it. Something like this will grow and I will want to make it as extendable as possible without having to break any of the core code. This is where OOP is perfect, the better choice.

 

In fact you have stated that you have used the CodeIgniter framework. This my friend is OOP. Again, I would not use a framework for a small task just because I know how to.

Share this post


Link to post
Share on other sites

Hi.[/size]

 

 [/size]

 

 

When I first discovered PHP Frameworks about a year ago, my friend suggested I get started using CodeIgniter (that seems to be a lot of newbies' first choice!). I loved it, but after reading various rantings and ravings on the internet I decided that I should probably move on to something more "professional". That's when I came up against SF2 and almost cried myself to sleep every night. It made no sense to me. It still makes no sense to me. I gave up.[/size]

SF2 is a dependency injection framework. It's probably a reach for you to expect to understand DI when you don't grasp the basics of oop.

 

 

After that I tried Laravel but couldn't even get going thanks to something called "Composer" which I still don't understand. I thought to myself, "I don't want to learn about dependencies at this stage, I just want to code". I gave up.[/size]

These days, the state of the art in PHP is component libraries, thanks to composer. You need to get it installed and learn the basics of it, if you want to bring yourself into the modern era of PHP. I should point out that Laravel's core is the symfony2 components. 

 

 

So after that, I decided to try and learn the basics of OOP and how/why it was better than procedural and I have to say - I don't think it is. And I kind of hate it. I find it really confusing and not one person I have asked is able to tell me why OOP is better than procedural. They say "it just is".[/size]

 

With all due respect, are you really in a position to judge the benefits of OOP? I understand if a master coder who can use OOP fluently wants to rail against it, but someone who admits they don't yet understand the basics of it, isn't really in a position to dismiss it.

 

Take the time to watch this video, and it should help you understand why Composer is important, and why component libraries are the state of the art in the PHP world (and why this was a long time coming and absolutely necessary for PHP to continue to compete with alternatives like node.js, python and Ruby).

 

 

Here's a 2 minute video on namespaces which are important to understand when using libraries and modern PHP OOP: https://knpuniversity.com/screencast/php-namespaces-in-120-seconds/namespaces

 

Here's a 14 minute video on composer: https://knpuniversity.com/screencast/composer/composer

 

After you have watched these videos, I hope you'll start to gain some clarity. After that you'll be in a position to begin to untangle frameworks (which are really a set of interdependent classes), and you might even be inspired to start to play with some of the individual symfony2 components. Try making a simple project that utilizes one or two components and just write some simple code.

 

A great one to start with for most people is: http://symfony.com/doc/current/components/finder.html

 

For example, you could write a simple script that uses the component to find all the files in a particular directory (and it's subdirectories), sort by name and list the files out. Try it with the special

$finder->in(__DIR__);
constant __DIR__ which will be the directory where your script is located.

 

With the component, it is literally something you should be able to write in 10 minutes or less, using only a handful of lines of code.

Share this post


Link to post
Share on other sites

×
×
  • 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.