• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 212
  • Last Modified:

end of one book and beginning of another. Based upon my ee questions, where should I go? Or use another book?

End of one book and beginning of another.  Based upon my ee questions, where should I go? Or use another book?

I am working in the beginning of Matt Zandastra objects patterns and practice 4th edition.
I may not understand, but at least I can follow in nusphere ide debug (call stack, local variables)

I am working at the end of Larry Ulman
 PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
where there is production level code.  No longer philosophical.  

<?php # login.php - 9.11
// This page both displays and handles the login form.

// Need the utilities file:

// Create a new form:
set_include_path(get_include_path() . PATH_SEPARATOR . 'C:/Users/Acer/AppData/Roaming/PEAR/pear/');
$form = new HTML_QuickForm2('loginForm');

// Add the email address:
$email = $form->addElement('text', 'email');
$email->setLabel('Email Address');
$email->addRule('required', 'Please enter your email address.');
$email->addRule('email', 'Please enter your email address.');

// Add the password field:
$password = $form->addElement('password', 'pass');
$password->addRule('required', 'Please enter your password.');

// Add the submit button:
$form->addElement('submit', 'submit', array('value'=>'Login'));

// Check for a form submission:
if ($_SERVER['REQUEST_METHOD'] == 'POST') { // Handle the form submission
    // Validate the form data:
    if ($form->validate()) {
        // Check against the database:
        $q = 'SELECT id, userType, username, email FROM users WHERE email=:email AND pass=SHA1(:pass)';
        $stmt = $pdo->prepare($q);
        $r = $stmt->execute(array(':email' => $email->getValue(), ':pass' => $password->getValue()));

        // Try to fetch the results:
        if ($r) {
            $stmt->setFetchMode(PDO::FETCH_CLASS, 'User');
            $user = $stmt->fetch();
        // Store the user in the session and redirect:
        if ($user) {
            // Store in a session:
            $_SESSION['user'] = $user;
            // Redirect:
    } // End of form validation IF.
} // End of form submission IF.

// Show the login page:
$pageTitle = 'Login';

Open in new window

Too many files (pear, htmlquickform_2). 5 lines in the call stack. Is this above my skill level?
too many files. Is this above my skill level
  • 3
  • 3
1 Solution
Ray PaseurCommented:
Zandstra is pretty advanced.  Plan on spending a considerable amount of time.

I don't think this is above your skill level as long as you can express in a natural language sentence what each line of code accomplishes.  If you can't do that, it's time to dig into the examples and documentation and clarify your understanding.

I also think you may want to ask a deep philosophical question about the if() statement.  Is there any circumstance in which I should omit the else{} clause?  The reason you want to think about this is because without the else{} clause you may find your programming doing something strange without any explanation.  Data-dependent problems, when the data enters the edge cases, are particularly troublesome when there is an if() without else{}.  If the only thing your else{} clause did for you was trigger_error() you would at least get a signal that something in your programming could not deal with an unexpected condition.

This is not a law or necessarily even a widely-held best practice.  It's just something to think about.
rgb192Author Commented:
so is the purpose of object oriented programming to eliminate else statement?
Ray PaseurCommented:
The purpose(s) of object oriented programming go a bit further.  I was talking about the code snippet posted with this question.

Look at lines 29, 32, 40, 46.  Each of them is an if() statement that only executes a block of code if the expression evaluates TRUE.  But what should the code do if one or more of those expressions evaluates FALSE?  Since there is no else{} clause associated with the if() statements, there is no useful alternative, not even a warning in the error_log.  That kind of programming is going to suffer a data-dependent failure some day, and whoever is dealing with it will be left scratching and wondering what went wrong.
[Webinar] Improve your customer journey

A positive customer journey is important in attracting and retaining business. To improve this experience, you can use Google Maps APIs to increase checkout conversions, boost user engagement, and optimize order fulfillment. Learn how in this webinar presented by Dito.

rgb192Author Commented:
That is alot of if statements from Larry Ulman.

so after 3 chapters of php introduction
there are 5 chapters of oop

and then chapter 9 is content management system which needs to be mostly procedural programming

but I think the code sample from chapter 9 is not really what I learned in the 5 oop chapters

I think all books towards the end produce projects which are practical and not philosophical.
But I rather learn oop.
Ray PaseurCommented:
Most PHP programming is a mix of procedural and object-oriented.  Even some of the best-written frameworks have procedural parts.  I believe the Facebook variant of PHP called Hack comes closer to a "real" OOP language.  You just have to use your judgement about these things.
rgb192Author Commented:
thanks for guidance and hack example

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 3
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now