nuxy Posted November 11, 2007 Share Posted November 11, 2007 Well, I hope this is the correct section to post this in. Anyways, I have been wondering, which is better/work. Like I recently saw something alike the following. Error_Reporting(E_NOTICE); Does this produce an error, or is it just someone trying to be neat/clean and making it uppercase. Also, with functions, I read somewhere, that the first character of a function/variable has to be lowercase and alphabetical. Is this true, and if so, why would scripts work with such things? Quote Link to comment https://forums.phpfreaks.com/topic/76856-php-function-upperlower-case/ Share on other sites More sharing options...
redbullmarky Posted November 11, 2007 Share Posted November 11, 2007 Also, with functions, I read somewhere, that the first character of a function/variable has to be lowercase and alphabetical. Is this true, and if so, why would scripts work with such things? have you tried it? function names are not case-sensitive, but the general rule of thumb is to write them as they've been set up. most (all?) built in functions are declared in lowercase, so it makes sense to keep it that way - it might make it clearer to read in some ways, but a) most syntax highlighters won't recognise it properly, hence making code harder to read and b) the confusion of seeing a function in a different case to the norm, coupled with not knowing if they're supposed to be case sensitive or not, might lead some coders who look at your work to think you're using a different function altogether - hence making it harder to understand. so yes - stick to how they're declared = less confusing for all. Quote Link to comment https://forums.phpfreaks.com/topic/76856-php-function-upperlower-case/#findComment-389125 Share on other sites More sharing options...
Orio Posted November 11, 2007 Share Posted November 11, 2007 Some people sometimes write the whole function name upper case and I know that they haven't got errors for that. Here, from the manual: Function names follow the same rules as other labels in PHP. A valid function name starts with a letter or underscore, followed by any number of letters, numbers, or underscores. As a regular expression, it would be expressed thus: [a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*. As you can see from the regular expression, the case doesn't matter. Orio. Quote Link to comment https://forums.phpfreaks.com/topic/76856-php-function-upperlower-case/#findComment-389134 Share on other sites More sharing options...
GingerRobot Posted November 11, 2007 Share Posted November 11, 2007 Personally, when using some functions - notably those in the gd libary, i do use some uppercase characters. Since those in the gd library don't use underscores, i find them a little hard to read - imageCreateTrueColor() is easier to read than imagecreatetruecolor() for me. Quote Link to comment https://forums.phpfreaks.com/topic/76856-php-function-upperlower-case/#findComment-389164 Share on other sites More sharing options...
Aureole Posted November 11, 2007 Share Posted November 11, 2007 I always wondered why people when making their own functions write the first part with a letter then user uppercase after. I use underscores mostly. Quote Link to comment https://forums.phpfreaks.com/topic/76856-php-function-upperlower-case/#findComment-389170 Share on other sites More sharing options...
Daniel0 Posted November 11, 2007 Share Posted November 11, 2007 Some claim it is easier to read. Other claims that using underscores is easier to read. It's just a matter of personal preference. Quote Link to comment https://forums.phpfreaks.com/topic/76856-php-function-upperlower-case/#findComment-389205 Share on other sites More sharing options...
zq29 Posted November 11, 2007 Share Posted November 11, 2007 Some claim it is easier to read. Other claims that using underscores is easier to read. It's just a matter of personal preference. Some might be fluent in JavaScript where the function names are case sensitive and do it out of habit... Quote Link to comment https://forums.phpfreaks.com/topic/76856-php-function-upperlower-case/#findComment-389206 Share on other sites More sharing options...
nuxy Posted November 11, 2007 Author Share Posted November 11, 2007 I think i'll try with underscores to identify functions made by me in the script. It can get rather frustrating having a function such as "stripslashes" and "strip_slashes", one that the person has made, and the other that is an built in php function. I normally, when making an OOP application use upper and lower case names. I use variables in arrays though, instead of something alike "user_name" and "user_id" I would just assign an array to it, "user[name]" and "user[id]". Some claim it is easier to read. Other claims that using underscores is easier to read. It's just a matter of personal preference. Some might be fluent in JavaScript where the function names are case sensitive and do it out of habit... Oh, I never knew Javascript was case sensitive, that's properly why most of my applications does not work. ): Quote Link to comment https://forums.phpfreaks.com/topic/76856-php-function-upperlower-case/#findComment-389208 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.