I am learning PHP with help of Wrox Beginning PHP5 but there aren't many practice question in there so can u guys know where I can find a whole bunch of PHP exercises? Kind of like homework/math problems. Where they get increasingly difficult and elaborate.
Practice I am looking for are on the following topics:
Decisions, Loops and Arrays.
Functions.
XML
Files & Directories.
Thanks in advance.
Regards,
appu.
You could try to come up with a web application to create. Forums, a Pythagoras solver etc.
http://projecteuler.net/
There are lots of questions on here like this, search for php project/challenge.
If I were you I'd come up with a small project for yourself, build a small website based on some interest you have. Implement basic things like logins, CRUD operations etc.
This will give you much more experience and build your knowledge quicker than completing small unrelated tasks.
Learning PHP is easy. In fact learning an language is easy. If you try learning it in the course of building a whole project your self it would teach you the practical implementation of functions and concepts. You can even search for projects on internet which will help you for having an start. I even learnt php in course of developing an project for my course work. Good Luck with your efforts.
Related
I'm pretty comfortable with both, and I've played around with a homemade authentication script, but I'm curious if you guys can recommend a project or undertaking or sorts to help me learn this better.
I was offered a job recently that asked for knowledge in MySQL, and that I'd be working with their databases. I'm pretty comfortable with MySQL, but I want to make sure I'm comfortable enough to please them incredibly.
Just choose something you'd like to do and try your best.
Practicing is the best way to learn, you have to deal with things you cannot find in books.
When I started with php I wanted to make a panel for a java games website, learnt a bit (never finished it) and then changed to a much ambitious project. Try different things, authentication, maybe a shopping cart, a blog, etc.. things like that tend to involve most of the things you might need in the future.
Good luck
The most effective way is to code something that you are not completely confident about before starting. Try to learn something new with every project - don't do all the stuff in the same way. What to code? Up to your imagination. Just don't forget being responsible when accepting jobs :))
Try writing something simple like a library book loan system that had multiple users many books with different authors and years located on different shelves or floors. Let your imagination run wild :)
Hello there I am new to php and want to learn to write reusable php code, a framework to build CMS for the sites that I am going to create.
From where should I learn such approach. If Possible please share some of the links of tutorials pdfs anything that can help me.
Try to re-invent the wheel. Read the TinyMVC source code and try building a framework similar to it. Then you can read and re-invent bigger framework. (I did this with Zend Framework, if you ask)
Of course, you should do this for learning purpose only. For your real projects, I suggest you to use existing PHP frameworks out there.
Like Michael said, don't re-invent the wheel.
You can choose from many frameworks when it comes to PHP. You might also consider using Ruby on Rails. In my experience, all 'good' PHP frameworks are just Ruby on Rails wannabes and bad at that too. But saying that is just begging for a flame war, so lets all pretend I didn't just say that.
---- on topic ----
You say that you are a beginning PHP-er and want to learn to 1. build reusable code and 2. build a CMS using 1.
An important practice of writing reusable code to me is that you split up functionality of a library you make up in as many parts as you can. To take a recent example of a digital store I am building, I would have a function that clears my shopping cart, one that clears the register one that resets the fields, etc. By splitting the code up in these different functions I was able to call some of them when a transaction was complete (with the addition of saving the transaction) and I when a search was completed (just reset the fields). Think of it like a chest of tools where you can either have screwdrivers attached to all the other tools, or you could just have 1 screwdriver. And this is just one aspect of it.
#Galwegian posted a good answer about more elements to reusable code on SO: How do you make code reusable? as well.
Learning how to build a CMS is a pretty broad question. If you were doing it just for the fun of it or just so to learn how to write better PHP; look around at what other CMSes are doing and wonder how they solved certain things, what makes them work or not and try to figure out how you can build that too.
If you want to build websites professionally; please don't create your own CMS. You will hate yourself for it later. Go for something with a wide user base and many tutorials, like drupal or wordpress. When building your own CMS you'll just be stuck wasting time finding solutions to problems that were already solved a lot better by others.
-- half topic---
I saw this PHP course coming by, it isn't free though, but it should get you started. Nettuts is a good resource for tutorials and alike either way, check it out.
http://net.tutsplus.com/tutorials/php/php-fundamentals-new-premium-course/
Why not just use one of the many many already existing PHP CMS frameworks out there?? Drupal, for example, is easy to extend. Don't re-invent the wheel.
Here is an example of Jeffery Way's tiny MVC framework which you could play with http://net.tutsplus.com/tutorials/php/create-your-first-tiny-mvc-boilerplate-with-php/
I was wondering how to do the PHP OOP design pattern for real life application. I wish someone can share their learning experience with me. I am particular interested in PHP and actionscript. Most of the books I could find in the book store are only basic PHP (or AS3) programming. I appreciate any help. Thanks!
Please do not close this topic..I am so desperate to know the answer since no one around me can help me about the topic. Stackoverflow is the best forum that many experts always help people when someone needs it.
I'm not sure if this is exactly what you're looking for but on the last couple Actionscript 3 projects I've developed I have used a combination of PureMVC and AMFPHP with great results. I am a PHP novice but know AS3 well. Hooking up a proxy to a AMFPHP service was pretty straightforward and using commands and notifications worked well.
If you're new to Actionscript or PureMVC you can find project skeletons that will help get you started.
I felt that PHP Objects, Patterns and Practice by Zandstra (ISBN13: 978-1430229254, ISBN10: 143022925X) was one of the most effective books when it came to upping my game in PHP. It covers patterns pretty extensively with some real world examples and clear explanations.
Now, given how new I am, I'm rather lost as to how I get started. Down the road, I want to use MVC framework so that I help myself be disciplined in the way I build. However, I know basic knowledge of PHP and OOP PHP are required. So my question is this: what are the right steps to mastering Cake PHP? I don't want to skip critical phases of learning before learning to Cake PHP. At the same time, I don't want to spend more time than required learning PHP if I can learn it directly through Cake PHP knowledge.
Any advice would be appreciated.
IMHO you should be comfortable writing at least a basic app in clean standard procedural code before using a framework. That means mastering all the basic elements of the language like if and switch, loops, functions, local and global variables, etc. It also includes being comfortable with HTTP GET and POST, RESTfulness and how to persist information between page loads (Cookies, Sessions, URL params). A basic idea of Javascript and AJAX would help as well.
Good exercises might include:
A page that outputs database contents and is paginatable, filterable and sortable by various fields.
A shop checkout process or similar "wizard"-like page.
That's when you can pick up a framework, since most frameworks abstract exactly these kinds of tedious things away from you. Especially Cake has a lot of automagic built in, which will leave you hopelessly confused if something goes wrong and you have no knowledge of the above mentioned. To start with OOP, you might want to try something like Zend first, which is a lot more transparent in how objects are used.
Deceze gives good advice, though I disagree that REST is a core concept for learning PHP. You can author a perfectly successful web app that isn't using the concept at all, and I don't think that you'd be hurt by learning it along with a framework.
The rest of his advice is good, however, and, so that you aren't out there on your own just crawling the web, I heartily recommend PHP and MySQL for Dynamic Websites by Larry Ulman. It won't teach you (much) about OOP, but it will give you a very solid foundation in PHP and MySQL, as well as how the two play together. More importantly, you'll cover a lot of core programming concepts applied to practical examples in PHP. This book was fundamental in my development as a programmer, providing baby steps and advanced techniques that made it a lot easier for me to digest more complex topics later on.
For a start, use the Cookbook
Although, I'd strongly suggest getting familiar with PHP itself first - any introductory level PHP book should suffice.
This one was by far the most useful for me
Build Your Own Database Driven Web Site Using PHP & MySQL, 4th Edition
http://www.sitepoint.com/books/phpmysql4/
It went through all the basics in a very logical way, and then challenged you to take some first steps on your own.
After reading this book, I'm at the same point. Whats the next step to understanding OOP, and implementing a framework like Cakephp...
I have been looking around online and I cant seem to find an article on this that isn't totally outdated. Does anyone have any good articles that give some good advice? What I have read so far is good, and a bit helpful, but I want to have modern code examples, not ones from 2002.
I have coded an extensive PHP/MySQL program and I am trying to make it better now, any suggestions?
EDIT:
People are suggesting frameworks, and I appreciate it but I am looking for coding tips for raw PHP Coding. The whole application is already done and it would be very lengthy to recode the entire thing in a framework.
I will be checking those out for future projects though. Does anyone know or have any tips for Writing Clean and Efficient PHP Code?
Use Smarty
Write to patterns as much as possible.
Edit for the Question Edit
Clean and efficient PHP isn't much different than any other language. Practice good Object oriented principles. Focus on Encapsulation, Separation, and Polymorphism. Refactor often, and Utilize design patterns as much as possible.
There are many sites that focus on these principles. Some use Java, C++, etc. to demonstrate the principles, but it shouldn't be too difficult to convert them over to php.
I'd take a look at the Zend Framework. It is a great framework that encourages PHP developers to use better practices like MVC, OOP etc. If you are not used to this paradigm, I have to say that it will seem daunting at first, but if want to continue with your PHP development I'd suggest downloading it, and start the "Getting Started" tutorial.
There are other frameworks, CMS tools that you can download, but the Zend framework offers are very raw approach to building great PHP applications.
Acorn
PHP Classes helped me a lot (when I was coding PHP). Reading better code usually helps improve my own.
If you haven't already, I suggest making your PHP code object-oriented. It promotes reuse and makes code a lot more readable. Here's a link to show how useful it can be for reducing lines of code etc.
Use CakePHP. It's an excellent MVC framework. Steep learning curve, especially if you've not used MVC before, but the tradeoff is certainly worth it.
Like folks said, frameworks are the way to organize your code best. Many support Model/View/Controller; many are object-oriented already. Try to stick with a PHP5-specific framework (the code will be much cleaner; PHP4 did not support OOP fully). Try to go with the simplest possible templating engine. One PHP5 framework I like that hasn't been recommended yet is called QCubed.
One thing in your post worried me, though - you're saying that you already have the application written, and are now trying to make it "better". If that's the case, trying to switch over to a framework now may be a HUGE (literally huge) task. If this is an application you expect to be in production for 3-5 years, I'd consider taking a plunge; I'd then try to take little pieces of the application and integrate them into that framework environment. Doing it wholesale is a recipe for pain.
For clean PHP code you can use PHP CodeSniffer (search for CodeSniffer on http://pear.php.net since direct links don't work) it's an automatic code style checker. You can define your own codestyle rules and then check the code.
You can even script it, so your code gets checked before SVN commit.