PHP Entry-level tutorials: PHP Case problems

Source: Internet
Author: User
Tags constant lowercase php class

Today, when you write code, you find an error in your code:

$m _category->insert ($data);

I called the Insert method of the $m_category object, and strangely, the Insert method name in my own frame is lowercase, but the first letter I call here is capitalized (the company's framework model class methods are all uppercase, sometimes used to go home to write code is not easy to write wrong).
But it is very strange that this code in the previous test is passed, and there is no error or what, the data is also normal to write, some think no solution, so try to do an experiment.
Let's start with the controller, I have a method in the current controller is Addwiki, then I add a method Addwiki, and then wait for a while, the IDE did not give me this new method error. With a sigh of relief, it seems that PHP is sensitive to capitalization. Then I tried to invoke Addwiki this way, and this time I was surprised that something happened: Php threw a fatal error at me: Addwiki cannot be redefined. It seems that PHP is not sensitive to the case of the method name.
Or do not give up, may be my PHP configuration problem, so the internet search, found a lot of information, the original PHP class name and method name is not sensitive to case.

Here is a copy of some of the information that distinguishes PHP from the case where it is sensitive.

1. Variable names are case-sensitive
2. Constant name default case sensitive
3. Function name, method name, class name is case-insensitive
4. Magic constant case-insensitive, recommended uppercase
5. NULL, TRUE, false is case-insensitive

Except that the variable name and the constant name are case-sensitive, the rest is indistinguishable. However, in our normal use, there are constant names, magic variables using uppercase habits, and null, TRUE, false in many frameworks are also recommended to use uppercase (although I prefer to use lowercase), so the problem is not. It is said that the constant name can be set to be case sensitive, but not to find this information, it is not clear, of course, or according to the Convention to use the capital bar.
It's all about class, method, function name. Well, I've always thought class and method names are case sensitive, so until now:-(
However, it is recommended to pay attention to the size of the good, after all, PHP does not know which version of the day to change this feature, no longer support the case insensitive function, method name

To give you a deeper look at the capitalization of PHP, we've sorted out some examples

First, case sensitive

1. Variable names are case-sensitive
All variables are case-sensitive, including ordinary variables as well as $_get, $_post, $_request, $_cookie, $_session, $GLOBALS, $_server, $_files, $_env, etc.

<?php
$ABC = ' ABCD ';
Echo $abc; Output ' ABCD '
Echo $aBc; No output
Echo $ABC; No output

2. Constant names are case-sensitive by default, and are usually written as uppercase
(but could not find a way to change this default configuration item, solve)


1 <?php
Define ("ABC", "Hello World");
Echo ABC; Output Hello World
ECHO ABC; Output ABC

3. PHP.ini configuration item directives are case-sensitive

such as File_uploads = 1 cannot be written file_uploads = 1

Second, not sensitive to case

4. Function name, method name, class name is not case-sensitive, but it is recommended to use the same name as the definition


<?php
Function Show () {
echo "Hello World";
}
Show (); Output Hello World recommended notation
Show (); Output Hello World

<?php
Class cls{
static function func () {
echo "Hello World";
}
}
Cls::func (); Output Hello World

5. Magic constant case-insensitive, recommended uppercase

Include: __line__, __file__, __dir__, __function__, __class__, __method__, __namespace__.


<?php
Echo __line__; Output 2
Echo __line__; Output 3

6. NULL, TRUE, false is case-insensitive


<?php
$a = null;
$b = NULL;
$c = true;
$d = TRUE;
$e = false;
$f = FALSE;
Var_dump ($a = = $b); Output Boolean True
Var_dump ($c = = $d); Output Boolean True
Var_dump ($e = = $f); Output Boolean True

7. Type casts, case-insensitive, including:

* (int), (integer) – Convert to integral type
* (BOOL), (Boolean) – Convert to Boolean
* (float), (double), (real)-Convert to floating-point
* (String)-Convert to String
* (Array)-Convert array
* (object)-Convert to Object

<?php
$a = 1;
Var_dump ($a); Output int 1
$b = (STRING) $a;
Var_dump ($b); Output string ' 1 ' (length=1)
$c = (string) $a;
Var_dump ($c); Output string ' 1 ' (length=1)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.