Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional PHP6
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional PHP6
This is the forum to discuss the Wrox book Professional PHP6 by Edward Lecky-Thompson, Steven Nowicki; ISBN: 9780470395097
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional PHP6 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old April 25th, 2013, 08:54 AM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Location: Indiana, United States
Posts: 13
Thanks: 3
Thanked 1 Time in 1 Post
Default Chapter 7 - Object Relation Mapping

So I am finally able to start working on the code for the object relational mapping. While working through that code I noticed that in the User::Save method there is a conditional that never will be evaluated.

Below is the code that I am referring to ( see 164-165 of the English version of the book ).

PHP Code:
// ....

eval('$actualVal = &$this->' $value ';');

if (isset(
$actualVal)) {
     
    if ((
is_int($actualVal)) || ($actualVal == NULL)) {
        
// other code....
    
}
}

// .... 
The second condition of $actualVal == NULL will never evaluate to true. This is because of the preceding isset() method call.

This is what the manual says about the isset() method.

http://us3.php.net/isset

So effectively it is extra code....

Please let me know if I am wrong or misunderstanding the code.
  #2 (permalink)  
Old April 25th, 2013, 09:15 AM
Friend of Wrox
Points: 651, Level: 9
Points: 651, Level: 9 Points: 651, Level: 9 Points: 651, Level: 9
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: May 2011
Location: North East UK
Posts: 125
Thanks: 0
Thanked 24 Times in 24 Posts
Default

Greetings,

Correct. The above "should" be like this;
Code:
eval('$actualVal = &$this->' . $value . ';');

if (isset($actualVal) || ($actualVal == NULL)) {
     
    if ((is_int($actualVal)) || ($actualVal == NULL)) {
        // other code....
    }
}
Assuming of course that 'null' is a possible value of '$actualVal'.

But then 'null' is a pain, but rather helpfull in a db.
The Following User Says Thank You to UseLess For This Useful Post:
ericrjones1 (April 25th, 2013)
  #3 (permalink)  
Old April 25th, 2013, 09:29 AM
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Apr 2013
Location: Indiana
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Why is "eval" even used in this book? I have always heard that you can't rely on "eval" because some hosting companies prevent its use.

Ever heard the term throwing out the baby with the bath water.
  #4 (permalink)  
Old April 25th, 2013, 05:45 PM
Authorized User
Points: 69, Level: 1
Points: 69, Level: 1 Points: 69, Level: 1 Points: 69, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Sep 2012
Location: Indiana, United States
Posts: 13
Thanks: 3
Thanked 1 Time in 1 Post
Default

Quote:
Originally Posted by UseLess View Post
Greetings,

Correct. The above "should" be like this;
Code:
eval('$actualVal = &$this->' . $value . ';');

if (isset($actualVal) || ($actualVal == NULL)) {
     
    if ((is_int($actualVal)) || ($actualVal == NULL)) {
        // other code....
    }
}
Assuming of course that 'null' is a possible value of '$actualVal'.

But then 'null' is a pain, but rather helpfull in a db.
Thanks for the reply, but now the first conditional statement doesn't make sense. To me, the first conditional statement is saying is the variable $actualVar isset (aka is it in PHP's memory stack and not null) or is it null.

So thinking about this more, maybe the following would work better. It reduces the nested if statements ( a possible source of increased code complexity ), and attempts to identify if $actualValue is null ( which PDO has a NULL parameter constant ).

PHP Code:

if (!isset($actualVal) || is_null($actualVal)) {
    
// set value to null in the database using PDO::PARAM_NULL
} elseif (is_int($actualVal)) {
   
// set value to int in the database using PDO::PARAM_INT
} else {
    
// set the value to string in the database PDO::PARAM_STR

Let me know what you think.
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 14 : Mapping data model to an object model robochrish BOOK: Beginning ASP.NET 4 : in C# and VB 8 March 5th, 2013 08:52 AM
Problem: Chapter 8 "Mapping Earthquakes Example" (Page 282) DrGaribaldi BOOK: Professional Android 2 Application Development 3 July 29th, 2010 06:24 PM
constraint for 1-to-n relation j_yan MySQL 0 December 10th, 2004 10:03 PM
Chapter 5-Image Mapping Help! maxcain Dreamweaver (all versions) 3 March 16th, 2004 08:00 AM



All times are GMT -4. The time now is 10:40 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.