Jump to content

PHP Function Upper/Lower Case


nuxy

Recommended Posts

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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. ):

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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