Jump to content
Larry Ullman's Book Forums

Search the Community

Showing results for tags 'oop'.



More search options

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • Single Editions
    • Modern Javascript: Develop and Design
    • The Yii Book
    • Effortless Flex 4 Development
    • Building a Web Site with Ajax: Visual QuickProject
    • Ruby: Visual QuickStart Guide
    • C++ Programming: Visual QuickStart Guide
    • C Programming: Visual QuickStart Guide
    • Adobe AIR: Visual QuickPro Guide
  • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (5th Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (4th Edition)
    • PHP 6 and MySQL 5 for Dynamic Web Sites: Visual QuickPro Guide (3rd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (2nd Edition)
    • PHP and MySQL for Dynamic Web Sites: Visual QuickPro Guide (1st Edition)
  • PHP for the Web: Visual QuickStart Guide
    • PHP for the Web: Visual QuickStart Guide (5th Edition)
    • PHP for the Web: Visual QuickStart Guide (4th Edition)
    • PHP for the Web: Visual QuickStart Guide (3rd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (2nd Edition)
    • PHP for the World Wide Web: Visual QuickStart Guide (1st Edition)
  • Effortless E-commerce with PHP and MySQL
    • Effortless E-Commerce with PHP and MySQL (2nd Edition)
    • Effortless E-Commerce with PHP and MySQL
  • PHP Advanced: Visual QuickPro Guide
    • PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide (3rd Edition)
    • PHP 5 Advanced: Visual QuickPro Guide (2nd Edition)
    • PHP Advanced: Visual QuickPro Guide
  • MySQL: Visual QuickStart Guide
    • MySQL: Visual QuickStart Guide (2nd Edition)
    • MySQL: Visual QuickStart Guide (1st Edition)
  • Other
    • Announcements
    • Newsletter, Blog, and Other Topics
    • Forum Issues
    • Social

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


Found 8 results

  1. Been studying your book for a while and noticed it is not too much different from the 4th edition. The book's using mysqli_ for database connection, and the php is still version 5.some. Meanwhile, php 7 has come to life and the pdo is ubiquitous nowadays. As well as MVC and more or less object oriented approach in general. Some books i know of (i'm not sure if i can mention them here) went through this and even their hands-on practice evolved from developing a simple CMS to an almost framework-like application. So, my question is: will you update your PHP & MySQL series?
  2. I'm having trouble understanding/linking the code example to the diagram and definition for the Factory Pattern. abstract class Shape { ... } class Rectangle extends Shape { ... } class Triangle extends Shape { ... } abstract class ShapeFactory { static function Create($type, array $sizes) { switch ($type) { case 'rectangle': return new Rectangle($sizes[0], $sizes[1]); break; case 'triangle': return new Triangle($sizes[0], $sizes[1], $sizes[2]); break; } } } $obj = ShapeFactory::Create($_GET['shape'], $_GET['dimensions']); Must be having an off day because I'm not seeing how the abstract factory class is being extended in the code example. I was unable to find any information in the book explaining the solid arrows or the term concrete, can anyone point me to the right pages, I must be going blind :/ Any help greatly appreciated. edit: ok I think I understand why there was confusion. The UML diagram used in the book is representative of the second reason/example given for using the factory pattern (where a base factory class is extended) but the code example references the first reason given for using a factory class and there is no UML diagram for this.
  3. I am a OOP-newbie - and I like this book a lot :-) None of the the two classes in the chapter, User and Page, have a $pdo in the constructer. This means that all db-handling(select, insert) is in the controller-pages and not in the classes. There could be a getUserName-method in the User-class, but no. I found another userclass on the internet where the $pdo is in the constructor, and then I can make a getUserName-method. BUT - if I then want to make some of the db-handling in the controller-page and not inside the class, the $pdo is required in the constructor, if I want to fetch data into my object. So I can't do that? Error: Missing argument 1 for User::__construct() It seems like that if I have the $pdo in the constructor, I MUST do all db-handling inside the class. And if I dont have the $pdo in the constructor I MUST do all db-handling outside the class(in the controller page). My question is: when should I have the $pdo in my constructor? Kim K
  4. In Chapter 5 on pate 157 it says in a darker portlet: I need some more details on this. What concerns me is that I created a file in which I included Rectangle.php then I declared a new class such as: class Square extends Rectangle { } just an empty class and then called: $r = new Square(); for testing purposes I added the following line to Rectangle's constructor class: print "construction called"; and it does seem to be executed when new Square class is instantiated with no parameters passed! Is the documentation in the book wrong or am I missing something? Because the above code indicates that the parent constructor seems to be called? Thanks in advance
  5. In this example why does the procedural way fail with this error: Error: Warning: mysql_fetch_assoc() expects parameter 1 to be resource, object given in /Users/joel/Sites/people_test/public_html/index.php on line 14 PHP: $dbc = @mysqli_connect (DB_HOST, DB_USER, DB_PASSWORD, DB_NAME) OR die ('Could not connect to MySQL: ' . mysqli_connect_error() ); $q = "SELECT first_name, last_name FROM person LIMIT 0,30"; $r = mysqli_query($dbc, $q); Procedural: while($data = mysql_fetch_assoc($r)) { $rows[] = $data; } //prints out null echo json_encode($rows); OOP: while($data = $r->fetch_assoc()) { $rows[] = $data; } echo json_encode($rows); I thought I was doing the procedural way right from reading the PHP.net fetch_assoc() procedural and oop examples. Obviously I'm missing something. Could use some help seeing what it is.
  6. version 0.5 Page 129 As I read this book, I keep scratching my head, wondering what's so good about OOP (Object Oriented Programming). The clips example is a case in point. Why write 5 lines of code when you can write just 2, like this? $stockQuote = 'AAPL: $533.25'; echo $stockQuote; I can modularize my procedural code by using includes. So how can all the fuss and bother of OOP be worthwhile? I've read plenty of rationales defending OOP, written by people who studied it in college, but it seems more like a religion to me. Sorry, I don't mean to offend anyone. I've read some books on OOP php, and I'm patiently reading through this one, only because I want to take advantage of the code that's automatically generated and tailored to whatever tables I need. But frankly, I will probably write most custom code, queries etc, as procedural php.
  7. Hello Larry, Thank you for all your help, I learned many things reading your books and now I am back to the desk for learning after many hours of producing. You were right that a programmer may have a very nice life doing procedural programming and I have to say that I finished a quite big project and I didn't mind 'repeating myself' as in fact was not that bad, put things in functions and the repeating part was rather easy: copy/paste and changing a few things. I like the fact that I can keep things separate, HTML, SQL, PHP, CSS. Anyway... I've got so used with your way and the patterns I learned from book that now I have a question related OOP. Is it a mistake if I use the same structure, for example the "configuration" file and the "connection" file and simply rewrite in oop syntax? Especially the database connection file that usually in frameworks does not stay outside the "http" folder. if I do write, let's say, a validation class for forms and for some project this is all that I need, is it a mistake that I do not create a CRUD class and other things like a framework has? I know it sounds like reinventing the wheel, but it is not quite like that. An existing framework has a lot of things that are useless to small projects and require maintenance that small projects do not necessary need. Why should I have the forms, for example, generated from PHP when, maybe, as part as my workflow, I prefer have them in HTML, so I can see them and work visually, like in Dreamweaver. I guess many with a background in design and not in programming would prefer it this way. Let's take for example Dreamweaver, it has some basic things that can do "programming for poets" and it is really fast, but it lacks a server side validation script. A simple validation class to resolve this issue will resolve a lot of problems and speed up the development. Will this be a bad thing ("unprofessional")? I look at your "Shopping Cart Widget" class in the book. You do not actually create a very general class and extend it afterwards in a framework style. It performs pretty particular things and probably can be abstracted more (a guess). Is that example just for study (as it compares with the procedural code before) or it may really be a production piece of code? If you add, let's say, real time quotes from Fedex, is it necessary to write a class "ShippingClass" than extend it with "ShippingFedexClass" when, assuming it is possible, writting just a functio in your Shopping Cart Widget class may provide shipping quotes? Bottom line, if we do not have very abstractizied classes for everything and keep things separate (things like forms, I believe this is a very good example), is this a mistake? Is it possible to have the best of both worlds? Thank you, Greg
  8. Hi, still teaching myself, Larry's books are great. As I am not in the computer field, when I go to places like PHP.net for info I usually can't figure out what they are really trying to say to me. I hope that my question below is proper for this forum, if not please excuse my question and I will respectfully withdraw it. I bought the PHP 5 Advanced book really to learn OOP, something very new to me. I am able to work through Larry's examples an do eventually get things to work when I modify the examples, to be sure I understand how the coding works. I took Script 3.1 db_sessions.inc.php and decided to turn it into an object, originally I wasn't able to get it to work no matter what I tried. On PHP.net I saw: "When using objects as session save handlers, it is important to register the shutdown function with PHP to avoid unexpected side-effects from the way PHP internally destroys objects on shutdown and may prevent the write and close from being called. Typically you should register 'session_write_close' using the register_shutdown_function() function." I tried to figure out what this meant but wasn't able to make my script work, until I found an example on the Internet in a chat room that initiated the the function like this below, not by just sending the objects, but by passing each of them in a different array along with a '$this' as a separate array item: session_set_save_handler( array($this,'OpenSession'), array($this,'CloseSession'), array($this,'ReadSession'), array($this,'WriteSession'), array($this,'DestroySession'), array($this,'GarbageCollectionSession')); Then everything worked, "CloseSession, ReadSession, WriteSession, DestroySession and GarbageCollectionSession are all objects that do their respective tasks. Can someone tell me why passing them as arrays with item [0] = "$this", and then item [1] = "TheObject" works, and also what kind of parameter have I passes. I would have not guessed that I could pass an array to a function in that manner without first assigning it to a variable? I am using XAMPP, PHP 5.3.8 and am on a Windows 7 PC. Any insight would be appreciated. Tony
×
×
  • Create New...