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

Posted on 2014-03-31
Last Modified: 2014-04-05
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
Question by:rgb192
  • 3
  • 3
LVL 109

Expert Comment

by:Ray Paseur
ID: 39969162
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.

Author Comment

ID: 39973904
so is the purpose of object oriented programming to eliminate else statement?
LVL 109

Expert Comment

by:Ray Paseur
ID: 39974838
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.
NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud


Author Comment

ID: 39980091
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.
LVL 109

Accepted Solution

Ray Paseur earned 500 total points
ID: 39980348
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.

Author Closing Comment

ID: 39980801
thanks for guidance and hack example

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article will explain how to display the first page of your Microsoft Word documents (e.g. .doc, .docx, etc...) as images in a web page programatically. I have scoured the web on a way to do this unsuccessfully. The goal is to produce something …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to count occurrences of each item in an array.

832 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question