I am just starting php. How to enrich my knowledge in PHP. Please help me to write better php code specially oops concept.
I can only advice three things.
read a lot.
I've some suggestions on how you might approach both topics:
The PHP language
If you want to get a deeper understanding of the language and learn about some best-practices, I've found http://www.phptherightway.com/ to be very useful, and it links to other tutorials and sources of good information.
It's also worth spending some time browsing the PHP manual, to learn about the various built-in functions.. oftentimes you can find yourself trying to re-implement some piece of functionality that already exists in the language itself.
You can learn about the OOP features of PHP from the manual, but it won't really help you to learn how to write good OO code - for that, you can learn a great deal from looking at other peoples code. Github is great for this because it makes it easy to browse around the source code of thousands of different projects. Find some well known figures from the PHP community and checkout their github repositories, see what you can learn from their code.
Most importantly, as claro says, is to practice. For many of us, the best way to really 'get' a concept is to build something using it. If you're reading up about PHP's session handling, write a small app to try out what you've learned.
Lastly, browsing forums like this one lets you see the kind of problems people commonly run into and different ways of solving them.
When developing on every project always include this common file ( can safely be used locally or online)
# set $path='your-project';
ini_set('error_log', $path .'/php_error.php');
defined('LOCALHOST') ?: define( 'LOCALHOST', 'localhost' === $_SERVER['SERVER_NAME'] );
// following parameters should already be set in your php.ini
# validate previous settings
if( -1 !== error_reporting() * ini_get( 'display_errors' ) ):
echo 'Webiswide we have a problem :(';
# ONLINE so do not show errors or warnings, etc
# error_reporting(1); // maybe, up to you
# debugging function
if ( LOCALHOST && (! function_exists('vd') )):
// vd( $anyVariable );
// vd( $anyVariable, 0 );
function vd($param, $mode=1)
Always check the value of a function otherwise one day you will get bitten
Just received this PHP email:
I would add setting timezone to that script. I think it is required since >= 5.3 and might lead to a lot of errors reported to the logs.
As the great philosopher Buffy Summers once pointed out, that is one thing repeated three times.
It's actually repeated twice.
This topic is now closed. New replies are no longer allowed.