A Sina PHP interview question, code output is related to the operating environment?

Source: Internet
Author: User
Write out the output of the following code:

try {
Include_once "AAA";
print "AAA";
} catch (Exception $e) {
print ' dddd ';
}
My answer is: If Include_path contains a file with AAA as its file name, the code outputs AAA. Otherwise output DDD.

The interviewer questioned my answer: The code is code, and there is only one possible output.

I cross-examine the test tube opposite answer:
You may think that I have answered the wrong question.

The interviewer (side) is skeptical of my technical ability after this question. The back of MySQL char (2) can save a few Chinese characters, because the Apprentice is not a precise answer. Then two sides directly to me in the treatment and opportunity to make a trade-off.

Reply content:

First interview doesn't have to answer ABC is correct ...
The most important is the process of thinking, for a lot of knowledge point extrapolate ability ...
The first question: The test is the difference between include and require
Include contains files that do not exist and will only throw warning,require that contain nonexistent files will be reported fatal error
So the problem will output DDD anyway because there will be no error, so it will not throw an exception ...
Conversely if the require contains, if the AAA file does not exist then an exception will be thrown, jump to the Catach code block, otherwise the output ddd

The second question: The test is the Chinese by byte how to store, char storage bytes
Utf-8 each Chinese corresponds to 3 bytes, and char (2) represents the row for that column storage take up to 2 bytes (no matter how many characters are stored)
So all 1 ways to store ...

If you can answer this, and extrapolate, the interviewer will certainly look after you oh ~

Latin1:

1character=1byte, 1 Kanji =2character (character),

In other words, a field is defined as varchar (200), it can store 100 characters or 200 letters.

This should be noted, especially when the field content is composed of letters and Chinese characters, as far as possible to assume that the field content is composed of Chinese characters, set the field length accordingly

UTF8:

1character=3bytes, 1 Kanji =1character (character)

In other words, a field is defined as varchar (200), it can store 200 characters or 200 letters.

Gbk

1character=2bytes,1 Kanji =1character (character)

In other words, a field is defined as varchar (200), it can store 200 characters or 200 letters. The first question after testing warning output AAA If replaced require also just to fatal Error:require () [function.require]: Failed opening required ' AAA ' ... And then nothing is going to be output, and no exception is thrown.
The second question has been tested to store 2 Chinese characters
CREATE TABLE ' Testchar ' (
' id ' int (one) not NULL auto_increment,
' AA ' char (2) not NULL,
PRIMARY KEY (' id ')
) Engine=innodb auto_increment=3 DEFAULT Charset=utf8;

INSERT into ' Testchar ' VALUES (' 1 ', ' ah ');
INSERT into ' Testchar ' VALUES (' 2 ', ' ah Ah ');
INSERT into ' Testchar ' VALUES (' 3 ', ' ah ah ah '); The code will have a Warning level error when a file with AAA as FileName is not found in Include_path: Failed to O Pen stream ..... When the file is present in Include_path, the code outputs "AAA".

I think this problem is actually to investigate include_once error will ignore the Try Catch statement this knowledge point. I was not a fine apprentice and answered only half the answer. So the interviewer asked: is the code only possible to have an output of the idea is correct?
  • 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.