If you are a web programmer, you need to know modern PHP. This book presents with many new areas in which PHP plays a large role. If you want to write a mobile application using geo-location data, Pro PHP Programming will show you how. Additionally, if you need to make sure that you can write a multilingual indexing application using Sphinx, this book will help you avoid the pitfalls. Of course, Pro PHP Programming gives a thorough survey of PHP post-5.3. You'll begin by working through an informative survey and clear guide to object-oriented PHP. Then, you'll be set for the core of the book on modern PHP applications. Now, you'll be able to start with the chapter on PHP for mobile programming and move on to sampling social media applications. You'll also be guided through new PHP programming language features like closures and namespaces. Pro PHP Programming deals with filtering data from users and databases next, so you'll be well prepared for relational and NoSQL databases. Of course, you can also learn about data retrieval from other sources, like OCR libraries or websites. Then the question of how to format and present data arises, and in Pro PHP Programming, you'll find solutions via JSON, AJAX and XML. What you’ll learn PHP 5.3 object-oriented programming and new PHP features Writing programs talking to SQL-based and NoSQL-based databases alike Using modern PHP programmer's tools Writing social media applications Investigating NoSQL datastores Writing PHP programs for a cloud ecology Who this book is for This book is for intermediate and advanced PHP programmers, as well as programmers coming from other languages such as Python, Perl, C/C++. It can also be utilized by programmers with knowledge of a previous PHP version who want to return to PHP. Table of Contents Object Orientation Exceptions and References Mobile PHP Social Media Cutting Edge Form Design and Management Database Interaction I Database Interaction II Database Interaction III Libraries Security Agile Development with Zend Studio for Eclipse, Bugzilla, Mylyn, and Subversion Refactoring, Unit Testing, and Continuous Intergration XML JSON and AJAX Conclusions Regular Expressions Cover 1 Contents at a Glance 3 Contents 422 About the Authors 430 About the Technical Reviewer 431 Foreword 432 Acknowledgments 433 Introducing PHP 5 Origins of PHP 5 What Is PHP? 5 HighLevel Overview of This Book 6 Chapter 1: Object Orientation 6 Chapter 2: Exceptions and References 7 Chapter 3: PHP on the Run (Mobile PHP) 7 Chapter 4: Social Media and PHP 7 Chapter 5: Cutting-Edge PHP 7 Chapter 6: Form Design and Management 7 Chapters 7 and 8: Database Interaction 7 Chapter 9: Oracle 8 Chapter 10: PHP Libraries 8 Chapter 11: Basic PHP Security 8 Chapter 12: Team Development with Zend Studio 8 Chapter 13: Refactoring Unit Testing 8 Chapter 14: XML and PHP 8 Chapter 14: JSON / Ajax 8 Chapter 15: Conclusion 9 The Future of PHP 9 Object Orientation 10 Classes 10 Inheritance and Overloading 12 Miscellaneous “Magic” Methods 17 The __get and __set Methods 17 The __isset Method 18 The __call method 18 The __toString() method 19 Copying, Cloning, and Comparing Objects 19 Interfaces, Iterators, and Abstract Classes 22 Class Scope and Static Members 26 Summary 28 Exceptions and References 29 Exceptions 29 References 34 Summary 38 Mobile PHP 39 Mobile Variance 39 Detecting Devices 40 The User-Agent 40 Built-in PHP Support 40 Detecting Mobile Capabilities 43 WURFL 44 Rendering Tools 56 WALL 56 Image Resizing 58 Responsive CSS 59 Emulators and SDKs 60 Developing on an Android 60 Adobe Flash Builder for PHP 60 QR Codes 61 Summary 62 Social Media 64 OAuth 64 Twitter 65 Public Search API 65 Private REST API 67 Using Twitter OAuth to Tie into Your Site Login 80 More API Methods and Examples 84 Facebook 87 Adding a Link to Log Out of Facebook 94 Requesting Additional Permissions 95 Graph API 96 Summary 98 Cutting Edge 99 Namespaces 99 Namespaces and Autoload 102 Namespaces Conclusion 103 Anonymous Functions (Closures) 103 Nowdoc 104 Local goto Statements 107 Standard PHP Library 108 SPL Conclusion 111 Phar Extension 111 Summary 114 Form Design and Management 116 Data Validation 116 Uploading Files / Images 123 Image Conversion and Thumbnails 124 Regular Expressions 126 Multi-Language Integration 130 Summary 131 Database Integration I 132 Introduction to MongoDB 133 Querying MongoDB 138 Updating MongoDB 142 Aggregation in MongoDB 144 MongoDB Conclusion 147 Introduction to CouchDB 147 Using Futon 148 CouchDB Conclusion 155 Introduction to SQLite 155 SQLite Conclusion 165 Summary 165 Database Integration II 166 Introduction to MySQLi Extension 166 Conclusion of the MySQLi Extension 173 Introduction to PDO 174 Conclusion of the PDO 177 Introduction to ADOdb 177 ADOdb Conclusion 182 Full-Text Searches with Sphinx 182 Summary 192 Database Integration III 193 Introduction to Oracle RDBMS 193 The Basics: Connecting and Executing SQL 196 Array Interface 199 PL/SQL Procedures and Cursors 202 Working with LOB types 206 Connecting to DB Revisited: Connection Pooling 211 Character Sets in the Database and PHP 213 Summary 215 Libraries 216 SimplePie 217 TCPDF 221 Scraping Website Data 228 Google Map Integration 234 E-mail and SMS 238 gChartPHP: a Google Chart API Wrapper 241 Summary 245 Security 246 Never Trust Data 246 register_globals 247 Whitelists and Blacklists 248 Form Data 248 $_COOKIES, $_SESSION, and $_SERVER 250 Ajax Requests 250 Common Attacks 251 Same Origin Policy 251 Cross Site Scripting (XSS) 251 Cross-Site Request Forgery (CSRF) 254 Sessions 255 Preventing SQL Injection 256 The Filter Extension 257 php.ini and Server Settings 261 Server Environment 261 Hardening PHP.INI 261 Password Algorithms 263 Summary 264 Agile Development with Zend Studio for Eclipse, Bugzilla, Mylyn, and Subversion 265 Principles of Agile Development 265 The Agile Development Rally 266 Introduction to Bugzilla 268 Mylyn for Eclipse 270 Bugzilla and Mylyn Combined Within Eclipse 272 Extrapolating the Benefits 276 Summary 277 Refactoring, Unit Testing, and Continuous Integration 279 Refactoring 280 Small Refactorings 280 A Larger Legacy Code Example 284 Unit Testing 298 Continuous Integration 316 Continuous Integration Server 317 Version Control 317 Static Analysis 318 Build Automation 319 Jenkins Server Setup 320 Summary 324 XML 325 XML Primer 325 Schemas 326 SimpleXML 327 Parsing XML from a String 327 Parsing XML from a File 328 Namespaces 333 RSS 336 Generating XML with SimpleXML 338 DOMDocument 343 XMLReader and XMLWriter 346 Summary 347 JSON and Ajax 348 JSON 349 PHP and JSON 350 Ajax 356 The Traditional Web Model 356 Ajax Web Model 357 Asynchronous Versus Synchronous Events 358 XMLHttpRequest Object 360 Using XMLHttpRequest 362 High Level JavaScript APIs 368 jQuery Examples 368 Sending Data to a PHP Script via Ajax 374 A Simple Graphic Program 376 Maintaining State 379 Summary 384 Conclusion 386 Resources 386 www.php.net 386 www.zend.com 387 devzone.zend.com 388 PHP| Architect Magazine: www.phparch.com 388 Conferences 388 PHP Certification 389 Summary 391 Regular Expressions 392 Regular Expression Syntax 392 Regular Expression Examples 394 Internal Options 396 Greediness 397 PHP Regular Expression Functions 398 Replacing Strings: preg_replace 398 Other Regular Expression Functions 400 Index 403 A 403 B 404 C 404 D 405 E 406 F 407 G 407 H 407 I 407 J, K 408 L 409 M 409 N 410 O 411 P 412 Q 414 R 414 S 415 T 417 U, V 417 W 418 X, Y, Z 418 Apress