Php programmer interview questions and answers

Source: Internet
Author: User
Php programmer interview questions and answers

  1. Class my_class
  2. {
  3. Function my_funct ($ my_param)
  4. {
  5. User_error ("please define me", E_ERROR );
  6. }
  7. Function B ()
  8. {
  9. Return 10;
  10. }
  11. }
  12. ?>

A. Multiple inheritance B. Interface C. abstract method D. private method E. function overload)

7. suppose a testclass class is defined. what is the name of its constructor? 15A. _ constructB. initializeC. testclassD. _ testclassE. constructor is supported only in pHp5.

8. how does one class override the default serialization mechanism? A. use the _ shutdown and _ startup methods B. call the register_shutdown_function () function C. use the _ sleep () and _ wakeup () methods D. cannot overwrite the default serialization mechanism E. use ob_start () to put the class into the output buffer.

9. Which of the following object-oriented concepts cannot be implemented in pHp4? Abstract class Final class public, private, protected (ppp) method interface A. abstract class B. ppp method C. ppp method and interface D. None of the above E. All of the above are available

10. how to call the mymethod method inside the class? A. $ self => mymethod (); B. $ this-> mymethod (); C. $ current-> mymethod (); D. $ this: mymethod () E. none of the above

11. what is the output of the following script?

  1. Class my_class
  2. {
  3. Var $ my_var;
  4. Function _ my_class ($ value)
  5. {
  6. $ This-> my_var = $ value;
  7. }
  8. }
  9. $ A = new my_class (10 );
  10. Echo $ a-> my_var;
  11. ?>

A.10B. NullC. EmptyD. nothing E. An error

12. what is the output of the following script?

  1. Class my_class
  2. {
  3. Var $ value;
  4. }
  5. $ A = new my_class;
  6. $ A-> my_value = 5;
  7. $ B = $;
  8. $ B-> my_value = 10;
  9. Echo $ a-> my_value;
  10. ?>

A.10B. 5C. 2D. NullE. nothing

13. what is the output of the following script?

  1. $ Global_obj = null;
  2. Class my_class
  3. {
  4. Var $ value;
  5. Function my_class ()
  6. {
  7. Global $ global_obj;
  8. $ Global_obj = & $ this;
  9. }
  10. }
  11. $ A = new my_class;
  12. $ A-> my_value = 5;
  13. $ Global_obj-> my_value = 10;
  14. Echo $ a-> my_value;
  15. ?>

A.5B. 10C. nothing. D. The constructor will report the error E.510.

14. Consider the following code. during execution, $ eight_tenths-> the string returned by the to_string method is 8/10 instead of the expected 4/5. why?

  1. Class fraction {

  2. Var $ numerator;
  3. Var $ denominator;
  4. Function fraction ($ n, $ d ){
  5. $ This-> set_numerator ($ n );
  6. $ This-> set_denominator ($ d );
  7. }
  8. Function set_numerator ($ num ){
  9. $ This-> numerator = (int) $ num;
  10. }
  11. Function set_denominator ($ num ){
  12. $ This-> denominator = (int) $ num;
  13. }
  14. Function to_string (){
  15. Return "{$ this-> numerator}/{$ this-> denominator }";
  16. }
  17. }

  18. Function gcd ($ a, $ B ){

  19. Return ($ B> 0 )? Gcd ($ B, $ a % $ B): $;
  20. }

  21. Function performance_fraction ($ fraction ){

  22. $ Gcd = gcd ($ fraction-> numerator,
  23. $ Fraction-> denominator );
  24. $ Fraction-> numerator/= $ gcd;
  25. $ Fraction-> denominator/= $ gcd;
  26. }
  27. $ Eight_tenths = new fraction (8, 10 );
  28. /* Reduce the fraction */
  29. Performance_fraction ($ eight_tenths );
  30. Var_dump ($ eight_tenths-> to_string ());
  31. ?>

A. the performance_fraction function must return a value of B. the performance_fraction function must accept an integer value C. there is a problem with the gcd function D. the $ eight_tenths object E must be passed by reference. object instances cannot be passed to structures other than methods.

15. what is the code below?

  1. Require_once ("myclass. php ");
  2. Myclass: mymethod ();
  3. ?>

A. static call of mymethod Method B. generate an instance of myclass and call the mymethod method C. generate a syntax error D. by default, the myclass class is created at the end and mymethod () E is called. call the function named myclass: mymethod ()

16. does pHp have static variables? A. There are B. no

17. what is the output of the following script?

  1. Class
  2. {
  3. Function a ($ x = 1)
  4. {
  5. $ This-> myvar = $ x;
  6. }
  7. }
  8. Class B extends
  9. {
  10. Var $ myvar;
  11. Function B ($ x = 2)
  12. {
  13. $ This-> myvar = $ x;
  14. Parent: ();
  15. }
  16. }
  17. $ Obj = new B;
  18. Echo $ obj-> myvar;
  19. ?>

A.1B. 2C. an error occurs because a: $ myvarD. warning is not defined because a: $ myvarE. nothing is defined.

18. how to load a class instantly? A. Use the _ autoload magic function B. define them as the forward class C. implement A special error handling method D. It is impossible E. use the conditional include to include them.

19. __________ provides a high-performance solution to the repeated problems in object-oriented systems? Answer :__________

20. what is the output of the following script?

  1. Class
  2. {
  3. Function ()
  4. {
  5. Echo \ parent called \;
  6. }
  7. }
  8. Class B
  9. {
  10. Function B ()
  11. {
  12. }
  13. }
  14. $ C = new B ();
  15. ?>

A. parent calledB. an error C. A warning D. nothing12. Next page

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.