Important Announcement
PubHTML5 Scheduled Server Maintenance on (GMT) Sunday, June 26th, 2:00 am - 8:00 am.
PubHTML5 site will be inoperative during the times indicated!

Home Explore No.Starch.Press.Object.Oriented.PHP.Concepts.Techniques.and.Code.210pp.6-2006

No.Starch.Press.Object.Oriented.PHP.Concepts.Techniques.and.Code.210pp.6-2006

Published by นฤเทพ พรหมเทศน์, 2017-11-19 00:48:06

Description: No.Starch.Press.Object.Oriented.PHP.Concepts.Techniques.and.Code.210pp.6-2006

Search

Read the Text Version

createFunction, SQLiteDatabase deprecated method, 155–156 coding styles, 167 functions, 129, 133 supported under PDO, 159createMethodArrays, Documenter class derived class, 8, 9, 76, 77 design patterns, 96 method, 131, 132 __destruct, magic method, 41,CSS (Cascading Style Sheet), 58–60, 111, 170 154, 155 destructor, 41 class name, 50 and configuring HTML freeing resources, 41 magic method, 41 components, 48 die function, 19, 20, 22 and reusability, 57, 58 replaced, 79, 82 used to configure components, direct access to data members, 26 DirectoryItems method getArraySlice, 54, 56current, iterator method, 86 58, 62, 64 DirectoryIterator class, 89D displaying objects, usingdata __toString, 78 hiding, 112 document element of an integrity, 26, 28, 43 members, 19 RSS file, 101 direct access to, 27 Document Object Model (DOM). protection, 12, 42 See DOMData Source Name (DSN). See DSN documentationdata type after assignment, 94database of built-in classes, 126 external, 126 abstraction, 157, 158, 159, 164 internal, 126 classes, 13 Documenter class connection, reusing, 68 formatting comments for, 136 queries, 63 methodsDATE, SQL function, 144date function, 135, 136 __construct, 132 createDataMemberArrays, 132date_default_timezone_set createMethodArrays, 131, 132 getConstants, 137 function, 154 getDocComment, 128, 135, 136datestamp field, mimicking, 141 getFullDescription, 130,debugging 131, 135 the ThumbnailImage class, 45 getName, 135 and undefined data getPublicMethods, 131, 132 DOM (Document Object members, 113default Model), 103 rewritten, 13 parameter, used with the double underscore, to denote constructor, 30 magic method, 28 values DSN (Data Source Name), for an for data members upon declaration, 38 SQLite database, 159 and order of method parame- dynamic method calling ters to PageNavigator, 73 statically, 96define function, 60 INDEX 181

E fetchAll, PDOStatement method, 160, 161, 164 Eckel, Bruce, 27 empty function, 161 fetchColumn, PDOStatement encapsulation, 12, 19, 112, 113, 122 method, 160 erratic behavior of a class, 52 error fetchObject, PDOStatement method, 161, 163 handling. See error trapping message with the ThumbnailImage final class, 45 __clone method, 122 trapping, 13, 75–76, 79, 83 and class originator, 78 error reporting level and inheritance, 78 E_ALL, 167 final class can't be extended, 95 E_ALL|E_STRICT, 167 final keyword, 78, 170 E_FATAL, 168 finally block, not implemented E_STRICT, 14, 18 in PHP, 84 when using PHP 4 coding floor function, 154 style, 18, 168 foreach loop, traversing an array, escaping 76, 86 database queries, 168 forward compatibility, 168, 170 input, with PDO, 160, 162 forward-only SQLite queries, 153, 154 cursor, 87 exception(s) result set, 87 re-throwing, 84 FOUND_ROWS, MySQL function, 70 throwing. See throw keyword function consistency of naming Exception class, 12–13, 76–77, 78, 80, 81 conventions, 15 library, 6 Exception methods prototype, 8 __toString, 77, 78 signature, 8 getCode, 77, 78 function keyword, 20, 170 getFile, 77 getLine, 77 G getMessage, 77 getTrace, 77 garbage collection, 41 getTraceAsString, 77 generic object class. See stdClass __get, magic method, 112–114, 115, execute, PDOStatement method, 162 executing multiple queries, 149 122, 123 export, Reflection method, 127–128, get and set methods, 43 get method with an aggregate 130, 131, 133 extends keyword, 80 class, 121 eXtensible Markup Language get_class function, 14, 171 get_class_methods function, 14, 171 (XML). See XML get_declared_classes function, F 129, 134 fetch get_declared_interfaces PDOStatement method, 163 function, 134 SQLiteResult method, 150 get_magic_quotes_gpc function, 153 get_parent_class function, 14, 171182 INDEX

getArraySlice, DirectoryItems Google method, 58, 70, 72 query string, 58 searches, 47–49, 56getCode, Exception method 77, 78getColumnMeta, PDOStatement Googlebot, 108 GoogleSearchResult, 107 method, 163 GoogleSearchService, 106getConstants, ReflectionClass Gosling, James, 2 method, 137 HgetDefaultProperties, ReflectionClass handling exceptions, 83 method, 137 helper method, 40getDocComment, Documenter class hover. See anchor pseudo-classes .htaccess file, 18 method, 128, 135, 136 HTML-encoded links, 54getElementById JavaScript htmlentities function, 105, 153 httpd.conf file, 166 function, 109getFile, Exception method, 77 IgetFullDescription, Documenter class identity operator, 119 method, 130, 131, 135 IIS (Internet Information Server),getLine, Exception method, 77getMessage, Exception method, 77 165, 166getMethods, ReflectionClass method, image function library, 36 image_type_to_mime_type function, 38 128, 129, 131, 132 imagecreatefrom group ofgetModifierNames, Reflection method, functions, 38 127, 132, 133 implementing an interface, 84–88getModifiers, ReflectionMethod implements keyword, 86 implode function, 133 method, 132, 133 in_array function, 151getName, Documenter class method, 135 information hiding, 12getNavigator, PageNavigator inheritance, 6–8 method, 54 and classes, 77, 78getParameters, ReflectionMethod important concept of OOP, 74 and interfaces, 84, 86 method, 129 initializing data membersgetProperties, ReflectionClass with constant values, 37 to document the data type, 37 method, 128 innerHTML property, 109getPublicMethods, Documenter method, instance(s) creating, 21–22 131, 132 defined, 6getRow MySQLResultSet method, 72 limiting the number, 68 variable declaration, 19 replaced by Iterator, 89 instanceof operator, 14, 133,getTrace, Exception method, 77getTraceAsString, Exception 168, 171 method, 77getUnlimitedNumberRows, MySQLResultSet method, 70, 73global variable $_SERVER, 62Google API, 100, 103, 104, 105, 108 developer's kit, 104 doGoogleSearch, 105, 106, 107 ResultElements array, 107 INDEX 183

interface(s) function, 20, 170 as abstract class, 9 implements, 86, 170 built-in, 12, 14 interface, 85, 170 defined, 7 parent, 169 different from abstract class, 92 private, 169 method and access modifiers, 88 protected, 77–78, 169 and multiple inheritance, 8 public, 169 synonym for public methods, 26 self, 67, 82, 169 static, 67, 170 interface keyword, 85 throw, 82 internal behavior of a class, 26, try, 83 27, 30 var internal comments, 136, 137 Internet Information Server (IIS). and PHP 4, 19 replaced in PHP 5, 26 See IIS is_a function, 14, 133, 168, 171 L is_object function, 129 __isset, magic method, 113, large software shops, 3 Lerdorf, Rasmus, 4 114, 170 libxml2, 13, 100 isset function, 113, 114, 151 LIMIT clause and SQL, 72 Iterator interface, 9, 14, 85–86 link. See anchor pseudo-classes Linux distributions supporting and arrays, 76 and SQLite result sets, 149 PHP 5, 165 iterator methods local variables, distinguishing from current, 85, 86, 87 key, 85, 86, 87, 88 instance variables, 30 next, 86, 87, 88 rewind, 85, 86, 87, 88, 89 M valid, 85, 86, 87 magic methods, 14, 28, 170 J __autoload, 115–116, 170 __call, 114–115 Java, 2, 4, 5, 11, 27, 41, 76, 88 used with MySQL class, 115 and constructors, 112 __clone, 79, 116, 117, Javadoc utility, 129, 136 119–121, 170 naming conventions, 19 __construct, 28, 111, 170 and PHP, 4 __destruct, 111, 170 as strongly-typed language, 94 __get, 112–114, 115, 122, 123, 170 __isset, 113, 114, 170 JavaScript, 100–104, 109 __set, 112–114, 115, 122, 123, 170 __set_state, 111 K __sleep, 116, 170 __toString, 78, 112, 116, 123, 170 key, iterator method, 85, 86, 87, 88 invoked by echo or print, 78 keywords __unset, 113, 114, 170 __wakeup, 116, 170 abstract, 88, 92, 169 and PDORow, 163 catch, 83, 170 used with MySQL class, 115 class, 19, 170 const, 82, 170 magic quotes, 154 extends, 80, 170 final, 78, 170184 INDEX

magic_quotes_gpc function, 168 NmatchNames, SQLiteDatabasePlus name/value pairs, 50, 51, 60, 63, method, 153–154 71, 73metadata, 101, 102, 151–153 natcasesort function, 134 queries, 160, 163 next, iterator method, 85, 86, 87 using the Reflection class to numeric array, 29, 31 NuSOAP, 13, 104 retrieve, 126method(s) O calling, 23 object(s) signature, 122 attribute of, 17 terminology for functions of a copying, 14 definition, 6 class, 20 displaying, using __toString, 78migrating from PHP 4 to returned by reference, 121 reusability of, 7–8, 63, 74 PHP 5, 166MIME type, 37 object method, calling, 22mod_rewrite. See Apache web server OOP (object-orientedmultiple inheritance, 3, 8, 84MySQL programming) assumptions of, 7 auto_increment as collaborative endeavor, 7 different from procedural database classes, 65–74 functions programming, 3–4, 7 and maintenance, 2 FOUND_ROWS, 70 operators SUBDATE, 154, 156, 164 arrow, 22 option, SQL_CALC_FOUND_ROWS, 70 assignment, 14–15MySQL improved. See mysqlimysql_connect function, 66, 67, 68, under PHP 4, 117, 170 under PHP 5, 117, 170 79, 82 assignment by reference, 22mysql_data_seek function, 70, 87 clone, 116, 118–121, 123, 170mysql_errno function, 79, 115 identity, 119mysql_escape_string function, 115 instanceof, 14, 171, 133, 168mysql_fetch_array function, 72, overloaded, 122, 123 reference, 15 87, 115 orphaned records, preventing, 144mysql_insert_id function, 115 overloadedmysql_query function, 66, 87 method, 122, 123mysql_select_db function, 66 operator, 122, 123mysql_stat function, 115 overridingMySQLConnect class, 66–69 defined, 80 parent class methods, 80, 81 private constructor, 97MySQLConnect methods P close, 68 PageNavigator class static getInstance method, 97, 98 inactive links, 50MySQLException class, 80–81 inactive spans, 53mysqli, 13, 149MySQLResultSet class, 69–70 INDEX 185MySQLResultSet methods getRow, 72 replaced, 89 getUnlimitedNumberRows, 70, 73

PageNavigator class, continued fetchColumn, 160 offset parameter, 60, 63 fetchObject, 161, 163 passing additional parameters, getColumnMeta, 163 50, 55, 71, 73 prepare, 160, 161–162 robustness, 63 and portability, 160 PageNavigator method, PEAR (PHP Extension and Applica- getNavigator, 54 tion Repository), 129, 158 paging through records, 70 Person class, 112, 113, 114, 117, 118 parent PHP class, 8, 77 culture, 4 constructor as hybrid language, 3, 12 installing, 166 invoking, 80, 81 as non-compiled language, 27 placement of call to, 132 as scripting language, 2 parent keyword, 81, 169 as typeless language, 122 pass by reference, 14, 118, 121, as web development language, 11 PHP 4 137, 170 porting code from, 118 call-time, 166–167 syntax, 12, 16 recommended way to, 167 PHP 5 pass by value, 15, 118 adoption of, 16 PDO (PHP Data Object), 13, Linux distributions 157, 159 supporting, 165 constants object model, 3 running under Windows, ERRMODE_EXCEPTION, 159 FETCH_LAZY, 163 165, 166 MYSQL_ATTR_USE_BUFFERED_QUERY, PHP Data Object (PDO). See PDO PHP Extension and Application 164 creating buffered result set, 161 Repository (PEAR). See drivers, 157, 158 PEAR installing, 158 php.ini file, 15, 104 SQLite-specific method, 159, 164 settings, 166, 167 and throwing exceptions, 159, 160 php_soap.dll, 104 and triggers, 164 php5apache.dll, 166 and views, 164 phpBB, 15 PDO methods phpDocumentor class, 129 prepare, 162 phpinfo function, 100, 141 query, 160, 161, 162 Plato, 21 quote, 160 polymorphism, 93 setAttribute, 159, 161 pragma sqliteCreateFunction, 159, 164 defined, 141 PDOException, 159 failing, 152 PDORow, 113, 161, 163 and metadata, 152 PDOStatement class, and multiple table_info, 151, 152 prefixes, 169 inserts, 162 prepare, PDOStatement method, 160, PDOStatement methods 161–162 and portability, 160 bindParam, 162 execute, 162 fetch, 163 fetchAll, 160, 161, 164186 INDEX

prepared statement, 13 ReflectionClass methods binding parameters, 162 getConstants, 137 replaceable parameter, 163 getDefaultProperties, 137 getMethods, 128, 129, 131, 132primitive data types, 6 getProperties, 128print or echo invokes __toString, 78print_r function, 78, 120 ReflectionException class, 126, 127,private 133, 135 access protecting data ReflectionFunction class, 126, 127, integrity, 26 133, 136 data members, accessing, 27 ReflectionMethod class, 126, 127, 128, method, 39–40 129, 131, 132, 133, 136 as internal behavior of a ReflectionMethod methods class, 39 getModifiers, 132, 133 getParameters, 129private keyword, 26, 169procedural programming, 3, 4, 23 ReflectionObject class, 126, 127, 136properties of an object, 19 ReflectionParameter class, 126, 127,protected keyword, 77–78, 169prototype JavaScript library, 104, 129, 132 ReflectionProperty class, 126, 127, 109, 110pseudo-variable $this, 20 128, 129, 133, 136, 137 Reflector interface, 126, 127, 133 not used with static variable, 67public access modifier, 28 register_shutdown_functionpublic keyword, 169public method, 27 function, 170pure abstract class, 92 remote procedure calls, 105 result set, as dependent object,Q 68–69query string used with reusability ThumbnailImage class, 45 of connection resources, 68query of objects, 63, 74 rewind, iterator method, 85, 86, PDO method, 160, 161, 162 SQLiteDatabase method, 148, 149 87, 88queryExec, SQLiteDatabase Rich Site Summary (RSS). See RSS root element. See document ele- method, 150quote, PDO method, 160 ment of an RSS file RSSR document element, 100–101read-only data members, 42 feed, 4, 13, 101readability, improving, 59 file format, 99records, paging through, 70 structure, 101–102reference version declaration, 101 avoid when cloning, 121 S operator, 15 return by, 28 schema, and sqlite_master table, 152Reflection class, 14, 127–128 scope resolution operatorReflection methods export, 127–128, 130, 131, 133 with a constant, 82 getModifierNames, 127, 132 replaces arrow operator, 67 and static class, 95 scripting language as glue, 2 self keyword, 67, 82, 169 INDEX 187

serialize function, 116 installing, 140, 142 server resources, 63 locking, 156 __set, magic method, 112–114, 115, documenting data types, 143 dumping a database, 140, 122, 123 __set_state, magic method, 111 141, 142 setAttribute, PDO method, 159, 161 field types, 143 setTableNames, SQLiteDatabasePlus functions and operators, 143 sqlite_master table, 141, 152, 163 method, 152 string concatenation SGML (Standardized General operator, 143 Markup Language), 100 support for transactions, 161 shallow copy, 120 version compatibility, 140, 142 show_methods function, 137 sqlite_escape_string function, Simple Object Access Protocol 154, 160 (SOAP). See SOAP sqlite_last_error function, 147 simplexml_load_file function, 102 sqliteCreateFunction, PDO method, SimpleXMLElement, 4, 13, 102–103 single inheritance, 8, 11 159, 164 singleQuery, SQLiteDatabase method, SQLiteDatabase 148, 149, 150 mixed return type, 148 class as final, 139 singleton class error messages, 147–148 and cloning, 122 executing multiple queries, 149 disallowing copies, 98 overriding query methods, singleton pattern, 96, 98 site-specific search, 103, 105, 108 146–150 __sleep, magic method, 116, 170 query methods, 160 SOAP (Simple Object Access SQLiteDatabase methods arrayQuery, 149, 150 Protocol), 13, 100, 103, constructor, 141, 145, 152 104, 105 createFunction, 155–156 SOAPClient class, 3, 13, 106, 108 SOAPFault class, 108, 127–128, 131 supported under PDO, 159 software shops, large, 3 query, 149 SPL (Standard PHP Library), 12, 76 queryExec, 149, 150 SQL singleQuery, 148, 149, 150 injection attack, 151, 162 statement, 70, 71, 72, 73 mixed return type, 148 SQLite, 13 and string reference argument, access control, 156 binary, 142 147–148 command-line, 141–142, 159 unbufferedQuery, 149–150 compared to MySQL, 141, 148, SQLiteDatabasePlus, converting util- 149, 154, 156 and concurrency, 159 ity methods, 160, 164 and data types, 143 SQLiteDatabasePlus methods database extracting metadata, 141, cleanData, 154 151–153 matchNames, 153, 154 format, 159 setTableNames, 152 SQLiteException, 141 SQLiteResult, 149, 160, 162 SQLiteResult method, fetch, 150 SQLiteUnbuffered, 160 sqrt function, 95 src attribute of img tag, 22, 44188 INDEX

Standard PHP Library (SPL). type in Visual Basic, 19 See SPL type hinting, 129, 133, 137, 168, 171Standardized General Markup Lan- arrays, 94, 137, 171 guage (SGML). See SGML exceptions, 83, 93, 94 and order of catch blocks, 93, 94statement, superior to a result parameters, 129 set, 163 and polymorphism, 94 return values, 129static data members, 67, 97, 98 U method, 67 calling, 95, 96 UDF (User Defined Function), 141, and pseudo-variable $this, 95 155–156 variables, referencing, 67 unbuffered result set, 87–88,static keyword, 67, 170 149–150stdClass, 163string concatenation operator in unbufferedQuery, SQLiteDatabase method, 149–150 SQLite, 143strtotime function, 154 undefined instance variables,struct, C data type, 19 112–113studly caps, 19, 20, 145subclass, 76 unserialize function, 116SUBDATE, MySQL function, 154, __unset, magic method, 113, 156, 164 114, 170subtracting dates, 155, 156 unset function, 33, 113superclass, 76 unsetting a connection, 68Suraski, Zeev, 11 upgradingsyntactic sugar, 122, 123syntax highlighting, 137 to PHP 5, 14–16, 18, 167systems analysis, 18 to SQLite 3, 159 URL-encoded, 51T User Defined Function (UDF).throw keyword, 82 See UDFthumbnail images, 36–39 user programmer. See client quality of, 43 programmerThumbnailImage class, 37–45 user-defined classes, 125, 126, 133, debugging, 45 134, 136, 137 query string used with, 45__toString, magic method, 77–78, V 80–81, 112, 116, 123, 170 valid, iterator method, 85, 86, 87 used to display objects, 78 var keywordtraversing a result set, 72trigger, 141–142, 143, 144–145, 156 and PHP 4, 19 definition, 141 replaced in PHP 5, 26 and referential integrity, 144 variant data type, 94 updating, 141 view, 141, 142, 143 field types, 152try updating, 141, 143, 144, 145 visibility block, 83 of instance variables, 19 keyword, 83 sorting by, 130, 131 visited. See anchor pseudo-classes INDEX 189

W wrapper method, 20–21, 67, 70, 115 WSDL (Web Services Definition W3C (World Wide Web Consortium), 100 Language), 104, 105, 106 __wakeup, magic method, 116, 170 X warnings, for deprecated functions, XHTML, 100 14, 15 XML (eXtensible Markup web developers, 1, 3, 4 web hosting, 16 Language), 13, 99–101 Web Service Definition Language XML toolkit, 13, 100 (WSDL). See WSDL Z web services, 13, 104, 105, 110 Zend engine, 15 well-formed XML document, 102 zend.ze1_compatibility_mode, 166 World Wide Web Consortium (W3C). See W3C190 INDEX


Like this book? You can publish your book online for free in a few minutes!
Create your own flipbook