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
195 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 110

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.
0
 

Author Comment

by:rgb192
ID: 39973904
so is the purpose of object oriented programming to eliminate else statement?
0
 
LVL 110

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.
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:rgb192
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.
0
 
LVL 110

Accepted Solution

by:
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.
0
 

Author Closing Comment

by:rgb192
ID: 39980801
thanks for guidance and hack example
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
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 …

690 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