Wrox Programmer Forums
|
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 software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 20th, 2010, 08:57 PM
Registered User
 
Join Date: Jan 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default PropertyObject Ch. 3

Hi,

I am looking at the code from the PropertyObject class in chapter 3.
There is just one thing I can't figure out.

On top of page 57 there is this piece of code:

Code:
if($this->propertyTable[$propertyName] != $value && 
                !in_array($propertyName, $this->changedProperties)) {
                    $this->changedProperties[] = $propertyName;
            }
I don't understand why we are testing the $value against $this->propertyTable[$propertyName]

I would think $this->propertyTable[$propertyName] will match a database table name and never match $value.

It would be understandable for me if $value would be checked agains $this->data[$this->propertyTable[$propertyName]]

Can someone please tell me what I am missing?

Thanks

Last edited by nativerun; July 22nd, 2010 at 06:47 AM..
 
Old July 22nd, 2010, 06:55 AM
Registered User
 
Join Date: Jan 2010
Posts: 5
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Ok, I have been checking the script by running it and see when the $changedProperties array get's a value assigned. Yes, I should have done that that before I posted the previous comment, sorry for that ;).

It indeed looks that what a stated is correct and this is an error in the code.

this piece of code on page 57:

Code:
if($this->propertyTable[$propertyName] != $value && 
                !in_array($propertyName, $this->changedProperties)) {
                    $this->changedProperties[] = $propertyName;
            }
should be changed to:

Code:
if($this->date[$this->data[propertyTable[$propertyName]] != $value && 
                !in_array($propertyName, $this->changedProperties)) {
                    $this->changedProperties[] = $propertyName;
            }
If you don't change this: the if statement will always be true (because "$this->propertyTable[$propertyName] != $value" will never match) and then the $changedProperties array will always be filled.

Cheers

Last edited by nativerun; July 22nd, 2010 at 07:05 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
Search ch 13, ch 16 sporik BOOK: Beginning PHP 6, Apache, MySQL 6 Web Development ISBN: 9780470391143 0 October 27th, 2009 04:44 PM
Ch 2 - Ex 2 jkiernander BOOK: Ivor Horton's Beginning Visual C++ 2005 0 December 29th, 2007 08:47 PM
Ch. 4 & Ch. 12 athena BOOK: Beginning PHP, Apache, MySQL Web Development ISBN: 978-0-7645-5744-6 0 July 23rd, 2004 10:54 AM
CH.15 NEED HELP stacy BOOK: Beginning ASP 3.0 1 January 21st, 2004 03:37 AM
ch. 2 with C# Justin BOOK: Beginning ASP.NET 1.0 1 July 10th, 2003 03:59 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.