Jump to content
Larry Ullman's Book Forums

titreader

Members
  • Content Count

    14
  • Joined

  • Last visited

Community Reputation

0 Neutral

About titreader

  • Rank
    Newbie
  1. It makes perfect sense now. Thanks for your time to clarify this and thanks for the great book you've written.
  2. According to the book when overriding a parent class must use the same number of parameters. Why is this? What happens when I pass one more parameter. I tested it by passing an extra parameter than the original (parent) signature and it works just fine so I failed to understand the idea behind having the same number of parameters. Can someone clarify this? Thanks
  3. Further to the above I think that the statement in the book is incomplete. The parent constructor is not called only when such is present on the child's class side. But it should make it clear that if the child's class does not have a constructor declared the parent one is automatically called
  4. In Chapter 5 on pate 157 it says in a darker portlet: I need some more details on this. What concerns me is that I created a file in which I included Rectangle.php then I declared a new class such as: class Square extends Rectangle { } just an empty class and then called: $r = new Square(); for testing purposes I added the following line to Rectangle's constructor class: print "construction called"; and it does seem to be executed when new Square class is instantiated with no parameters passed! Is the documentation in the book wrong or am I missing something? Because the above code indicates that the parent constructor seems to be called? Thanks in advance
  5. I just passed the section of phpdoc about couple of days ago and all worked like a charm. I know this is of any help to you but at least I can confirm that it works as described in the book so you can concentrate on looking for a problem on your side. All I had to do is cd into the directory with the file I want to document and run: phpdoc -f HelloWorld.php -t docs Of course change HelloWorld.php with whatever your file name is and 'docs' with whatever directory you want to generate the documentation in
  6. I still can't figure out what I've changed to make it work. I did rewrite everything so I guess I've initially made a stupid error in my code which I did not in the re-write.
  7. Hello Antonio, I've been messing around with the code and out of the sudden I got it working. I will try to find out what exactly was the problem. Just wanted to say big thanks for your help!
  8. print $sid in read_session() function produces the desired output. That is why I first thought to set session_id($sid) but that did not help either.
  9. Hi Antonio, $data is already serialized as it comes directly from DB. And as per PHP manual it is written there in a serialized form. The error reporting did not bring anything new. Just got an idea how to present you the whole picture. You may download the actual code of the book from here: http://www.larryullman.com/downloads/phpvqp3_scripts.zip Unzip it and navigate to Ch03 folder (unfortunately this requires an active DB connection and session table) but you may get around it. So all the functions are in db_session.inc.php What I am trying to achieve is to run sessions.php and print the session_id(). In my case it is always an empty string and I am fighting to understand why. Thanks for your help so far!
  10. In the tutorial from the book we use this function and a couple of other function like this: // Declare the functions to use: session_set_save_handler('open_session', 'close_session', 'read_session', 'write_session', 'destroy_session', 'clean_session'); // Make whatever other changes to the session settings, if you want. // Start the session: session_start(); This is actually the end of the db_sessions.inc.php file. So I don't call this function directly but php does when I call $_SESSION
  11. Ah sorry. I've been think all the time that you actually have the book. So this is the function that reads the session from DB located in db_sessions.inc.php [i am providing file names for consistency]: // Define the read_session() function: // This function takes one argument: the session ID. // This function retrieves the session data. // This function returns the session data as a string. function read_session($sid) { global $sdbc; session_id($sid); // Query the database: $q = sprintf('SELECT data FROM sessions WHERE id="%s"', mysqli_real_escape_string($sdbc, $sid)); $r = mysqli_query($sdbc, $q); // Retrieve the results: if (mysqli_num_rows($r) == 1) { list($data) = mysqli_fetch_array($r, MYSQLI_NUM); // Return the data: return $data; } else { // Return an empty string. return ''; } } // End of read_session() function. db_sessions.inc.php starts the session at the end of the file. This file is included in another file called sessions.php Now If i print session_id() in the sessions.php file it returns an empty string. I am failing to understand why! As you can see php passes the session id hash to this function when reading the session. As per the manual: http://php.net/manual/en/function.session-id.php one can print the session hash with print session_id() and this is working fine using the default session mechanism of php. When I however change to store the session into DB as per Larry's book session_id() seems to stop functioning. So once you start the session php seems to correctly record it into DB. But if I decide to get the session hash it does not work.
  12. Hi Antonio, read_session() expects $data to be returned as per the book and the manual so I cannot return session_id(). As per the manual if I am not using database for sessions I can just issue print session_id() and it would print the session hash. But when I switch to database sessions the session_id() function seems to loose its ability and I can't figure out why.
  13. Everything is as per the book and works. The only thing I've added to the read_session() function is the following line of code: session_id($sid); This is in the db_sessions.inc.php file. Session is started at the end of the file and the whole file is included into sessions.php where I try to print session_id() but nothing.
  14. Hello, Just read through sessions in Ch3. There is one thing I did not get. How do I obtain the session_id(). It seems to be always empty. I even tried to set it in the read_session() but still no effect. Is this the expected behavior or am I missing anything? Cheers
×
×
  • Create New...