Monday, October 3, 2011

html_entity_decode() & htmlentities()

htmlentities() — Convert all applicable characters to HTML entities
html_entity_decode() is the opposite of htmlentities() in that it converts all HTML entities to their applicable characters from string.
html_entity_decode — Convert all HTML entities to their applicable characters

How to find number of arguments passed in a function in php?

func_num_args — Returns the number of arguments passed to the function

example:
                                                        function foo()
                            {
                                              $numargs = func_num_args();
                                              echo "Number of arguments: $numargs\n";
                            }

                            foo(1, 2, 3); 
                            ?>

Session and Cokkies

COOKIE
            A cookie is a text-only string that takes a place in the memory of user’s browser.
            If the lifetime of the cookie is set to be longer than the time user spends at that site, then this string is saved to file for future reference. User could be disabled the cookie in their browser setting.

SESSION
            Session values are store in server side not in user’s machine.
           A session is available as long as the browser is opened. User couldn’t be disabled the session. We could store not only strings but also objects in session.

The Differences
           1. The key difference would be cookies are stored in client side and sessions are stored in server side.
           2. The second difference would be cookies can only store strings. We can store our objects in sessions. Storing objects in sessions were really useful according to my experience.
           3. Another difference was that we could be save cookie for future reference, but session couldn’t.
           When users close their browser, they also lost the session.

Difference between fputs and fwrite

1. The fputs() writes to an open file.
2. The function will stop at the end of the file or when it reaches the specified length, whichever comes first.
3. This function returns the number of bytes written on success, or FALSE on failure.
4. The fputs() function is an alias of the fwrite() function.
5. There is no difference between fputs and fwrite, fputs() function is an alias of the fwrite() function.

Difference between include and require

1. The two functions are used to insert the content of a file into another PHP file before it is executed by the server.
2. They are identical in every aspect, but they perform error handling in different ways.
3. The include() function generates a warning (which does not halt execution) while the require() function generates a fatal error (which stops execution immediately).

Error display functions

              1.ini_set('display_errors', 1);
              2.ini_set('log_errors', 1);
              3.ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
              4.error_reporting(E_ALL);

Method Overriding

Method overriding is when the function of base class is re-defined with the same name, function signature and access specifier (either public or protected) of the derived class.