Solved

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
6
185 Views
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:
require('includes/utilities.inc.php');

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

// Add the email address:
$email = $form->addElement('text', 'email');
$email->setLabel('Email Address');
$email->addFilter('trim');
$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->setLabel('Password');
$password->addFilter('trim');
$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:
            header("Location:index.php");
            exit;
    
        }
        
    } // End of form validation IF.
    
} // End of form submission IF.

// Show the login page:
$pageTitle = 'Login';
include('includes/header.inc.php');
include('views/login.html');
include('includes/footer.inc.php');
?>

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
0
Comment
Question by:rgb192
  • 3
  • 3
6 Comments
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
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.
0
 

Author Comment

by:rgb192
Comment Utility
so is the purpose of object oriented programming to eliminate else statement?
0
 
LVL 108

Expert Comment

by:Ray Paseur
Comment Utility
The purpose(s) of object oriented programming go a bit further.  I was talking about the code snippet posted with this question.
http://www.experts-exchange.com/viewCodeSnippet.jsp?refID=28401769&rtid=10&icsi=1

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.
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:rgb192
Comment Utility
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.
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
Comment Utility
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.
0
 

Author Closing Comment

by:rgb192
Comment Utility
thanks for guidance and hack example
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

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 …
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…
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

744 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

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now