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.
Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center


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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
I'm getting too many results in this SELECT statement. How can I fix it? 6 58
What is wrong with this PDO Delete Query? 2 17
Help with PHP 13 27
PHP Mail error 3 28
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

830 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