For example, the function strtoupper() is simple and straight forward but when I don't use it for a while, I can't recall exactly if it's supposed to be upper(), toupper(), or stringtoupper().....
Any experienced coders have any suggestions on how I can remember php syntax better?
Any tips on remembering PHP code?
"http://www.php.net/name_of_function"
Most of the time, if you replace "name_of_function" with something fairly close, you'll get a list of best guesses as to what you are looking for (or the actual page if you guessed closely enough).
Also, many IDE's developed with PHP in mind have auto-complete functions, so if you start typing 'strt', a tooltip will pop up with 'strtok', 'strtolower', 'strtoupper', etc.
yeah, If I forget a function name I'll just google something like
"PHP upper case characters" and I'll figure out what I am missing
Almost all PHP functions shorten string to str
sub_str
strstr
strtoupper
strtolower
strcmp
...
The only real catch is some are str_* ... like str_replace
Other than that, it is just remembering (or guessing) the abbriviation for the word.
i.e. nl2br
New Line 2 br
ltrim and rtrim
Left trim and right trim
The array functions are a bit trickier, but 60%+ start with array_* and the rest are pretty obvious they go with an array ... such as count, sort, cur, next, etc...
Also, heed NogDog's suggestion ... I've been accessing php.net that way for years now and it is a real time saver ... mysql.com is pretty close to the same way.
In any case, rest assured that none of us has memorized every PHP function; there are too many of them for that. (Well, maybe Weedpacket has, but we're not sure he [it?] is really human. :p )
In any case, rest assured that none of us has memorized every PHP function; there are too many of them for that. (Well, maybe Weedpacket has, but we're not sure he [it?] is really human. )
yeah, that's what i'm thinking exactly, you have to be an android like Data from Star Trek:TNG to be able to memorize them, especially with so many web techologies out there (javascript, xml, mysql,.....) it's humanly impossible to write codes without any references and if you can, then you're probably not human because the human brain isn't designed to memorize but to solve problems so let's stick to what we do best and leave memorizing to the robots....
NogDog;10897615 wrote:In any case, rest assured that none of us has memorized every PHP function; there are too many of them for that. (Well, maybe Weedpacket has, but we're not sure he [it?] is really human. :p )
Memorizing every function / language construct would require photographic memory, which we all have.. just that most of use are born without film.
As for Weedpacket, I once intercepted a transmittion he was sending back to his homeworld located in some galaxy dubbed NGC 3561, basically mocking our 'pityful and utterly rudimentary web languages' which his newborn quickly grew bored of...
But he doesn't know that I know.. so... shhhh, in case he's listening...
nrg_alpha;10897680 wrote:As for Weedpacket, I once intercepted a transmittion he was sending back to his homeworld located in some galaxy dubbed NGC 3561, basically mocking our 'pityful and utterly rudimentary web languages' which his newborn quickly grew bored of...
But he doesn't know that I know.. so... shhhh, in case he's listening...
hehehe....who is this 'Weedpacket'
One of the things i find difficult to work with is regular expressions and their many flags and quantifiers. Some flags like /s, /x, /U, /m......don't really stand for anything and there's no way to relate their syntax to what they actually do. How do you deal with that?
trained_monkey wrote:hehehe....who is this 'Weedpacket'
One of the users here, but I suspect you already knew that :p
trained_monkey wrote:One of the things i find difficult to work with is regular expressions and their many flags and quantifiers. Some flags like /s, /x, /U, /m......don't really stand for anything and there's no way to relate their syntax to what they actually do. How do you deal with that?
Just refer to the manual whenever you forget
That said, they usually are abbrevations of some sort that can be used as mnemonics. For example, it is easy to remember that the m modifier has something to do with "multiline", or that the U modifier has something to do with "Ungreedy" (but then you might mix it up with u).
trained_monkey;10897845 wrote:hehehe....who is this 'Weedpacket'
Go into any other forum and call him out.. You'll see who he is
trained_monkey wrote:One of the things i find difficult to work with is regular expressions and their many flags and quantifiers. Some flags like /s, /x, /U, /m......don't really stand for anything and there's no way to relate their syntax to what they actually do. How do you deal with that?
This site is a good start, as is the php manual.
As you continue to play with regex, it all starts to fall into place.. Unlike anything else, practice, practice and practice some more..
Thanks for the tips.
Also, do you have any suggestions on functions that take 0 or more parameters? I get the order of the parameters mixed up sometimes.
trained_monkey wrote:Also, do you have any suggestions on functions that take 0 or more parameters? I get the order of the parameters mixed up sometimes.
What kind of suggestions are you looking for? PHP does not have a built-in mechanism for providing formal parameter names when passing actual arguments, so you can only rely on parameter position. (But there are other ways, e.g., passing an associative array.)
trained_monkey;10897898 wrote:Thanks for the tips.
Also, do you have any suggestions on functions that take 0 or more parameters? I get the order of the parameters mixed up sometimes.
I don't remember, but dreamweaver does for me and is constantly reminding me. Other text editors or ide's do the same thing. Like if I type substr then it will pop up and say: substr(string str, int length, [int length])
laserlight;10897900 wrote:What kind of suggestions are you looking for?
For example, the function preg_split(pattern, string [, limit [, flags ]]) takes 4 arguments (pattern, string, limit, flags), but sometimes I get the order of the arguments wrong (string, pattern, flags, limit). What is the best way to get the order right?
It would be more efficient if I didn't have to refer back to php manual all the time when writing code. I'm in a hurry :rolleyes:
trained_monkey wrote:What is the best way to get the order right?
As nrg_alpha said, practice.
Some editors have pop-up code hints that, depending on the editor and configuration options, will pop up automatically or upon some hot-key or such. The code hint will show the list of function parameters with a brief description of each.
Do you know of any free editors that has that feature? foyer mentioned Dreamweaver but that's a bit expensive. Right now I'm using Notepad++, it has syntax highlighting for dozens of languages but doesn't have that feature.
Aptana Studio is one option for an open-source tool. I currently use phpDesigner, which is not free but is a heck of a lot cheaper than Dreamweaver. (You can get phpDesigner 2007 as freeware, but I don't know if the free version includes the code-hinting or not -- you'll have to try it yourself to find out.)