background preloader

Php

Facebook Twitter

Zend Framework Manual. Variable handling Functions. Object Interfaces. I was wondering if implementing interfaces will take into account inheritance. That is, can inherited methods be used to follow an interface's structure? <? Php interface Auxiliary_Platform { public function Weapon(); public function Health(); public function Shields(); } class T806 extends T805 implements Auxiliary_Platform { public function Weapon() { var_dump(__CLASS__); } public function Shields() { var_dump(__CLASS__ .

"->" . __FUNCTION__); } } $T805 = new T805();$T805->Weapon();$T805->Health();$T805->Shields(); echo "<hr />"; $T806 = new T806();$T806->Weapon();$T806->Health();$T806->Shields(); ? If the code were to be the same, but instead T805 (or T806) DOES NOT implement Auxiliary_Platform, then it'll still work. This seems to work in PHP5.2.9-2, PHP5.3 and PHP5.3.1 (my current versions). We could also do the opposite: class T805 { public function Weapon() { var_dump(__CLASS__); } } $T805 = new T805();$T805->Weapon();

Debugging techniques for PHP programmers. Introduction There are many PHP debugging techniques that can save you countless hours when coding. An effective but basic debugging technique is to simply turn on error reporting. Another slightly more advanced technique involves using print statements, which can help pinpoint more elusive bugs by displaying what is actually going onto the screen. PHPeclipse is an Eclipse plug-in that can highlight common syntax errors and can be used in conjunction with a debugger to set breakpoints. Setting up To learn the concepts described in this article, you are going to need PHP, a Web server, and Eclipse. We need a Web server to parse the pages you create in PHP and display them to the browser. To take advantage of some of the debugging techniques in this article, you need to install Eclipse V3.1.1 and the plug-in: PHPeclipse V1.1.8. You also need the debugger module extension for PHP. See Resources for download information.

Back to top Error messages Error reporting in PHP Testing error reporting <? Variable variables. Sometimes it is convenient to be able to have variable variable names. That is, a variable name which can be set and used dynamically. A normal variable is set with a statement such as: A variable variable takes the value of a variable and treats that as the name of a variable. In the above example, hello, can be used as the name of a variable by using two dollar signs. i.e. At this point two variables have been defined and stored in the PHP symbol tree: with contents "hello" and with contents "world". Therefore, this statement: produces the exact same output as: i.e. they both produce: hello world. In order to use variable variables with arrays, you have to resolve an ambiguity problem. Class properties may also be accessed using variable property names.

Curly braces may also be used, to clearly delimit the property name. Example #1 Variable property example <? $foo = new foo();$bar = 'bar';$baz = array('foo', 'bar', 'baz', 'quux');echo $foo->$bar . $arr = 'arr';echo $foo->$arr[1] . Warning. Login example with Zend_Auth ~ Robert Basic. Happy New Year! Hope everyone had a blast for New Year's Eve and managed to get some rest :) This is my first working day for this year. I'm still kinda lazy and sleepy. And I wanna eat something all the time. Damn you candies!!! So, here's what I'm going to do: authenticate an user against a database table using Zend Framework's Zend_Auth component. Preparation Because I'm gonna use a database, be sure to have set the default database adapter in the bootstrap file, I have it setup like this: $config = new Zend_Config_Ini('..

$config = new Zend_Config_Ini('.. I'll need it later in the code. -- -- Table structure for table `zendLogin` -- CREATE TABLE `zendLogin` ( `id` int(11) NOT NULL auto_increment, `username` varchar(32) NOT NULL, `password` varchar(32) NOT NULL, `name` varchar(100) NOT NULL, `email` varchar(100) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 AUTO_INCREMENT=2 ; The login controller The magic happens in the LoginController. // is the user a valid one? Login and Authentication with Zend Framework - phly, boy, phly. Login and Authentication with Zend Framework Update: this article is now available in French, courtesy of Frédéric Blanc. I've fielded a number of questions from people wanting to know how to handle authentication and identity persistence in Zend Framework. The typical issue is that they're unsure how to combine: An authentication adapter A login form A controller for login/logout actions Checking for an authenticated user in subsequent requests It's not terribly difficult, but it does require knowing how the various pieces of the MVC fit together, and how to use Zend_Auth.

Authentication Adapter For all this to work, you'll need an authentication adapter. Our login controller will make use of the adapter, but simply have a placeholder for retrieving it. Login Form The login form itself is pretty simple. Username must be alphabetic characters only, and must contain between 3 and 20 characters Password must consist of alphanumeric characters only, and must be between 6 and 20 characters <? PHP Tutorial: Writing Your First PHP Script: A Feedback Form (a FormMail Script) Getting Started with PHP: Write a FormMail Script in PHP by Christopher Heng, thesitewizard.com I have always believed that the most fun way to learn a new programming language, whether it is a language like C or a scripting language like PHP, is to use it to write a real-life useful program.

Of course this is not the most systematic method of learning, but it works well if you already have some background in programming. Preliminaries Before you write your first PHP program, make sure that your website is running on a web host that runs PHP 4.1 or above. I will begin with a very rudimentary (but working) PHP script to take input from a feedback form and send it to you in an email message. If you are programming-savvy, you will recognize this as a sort of "Hello World" program, but infinitely more useful! Writing the Feedback Form The first thing we need to do is to write the feedback form itself. The Feedback Form PHP Script Now all that remains is to code "sendmail.php".

Conclusion. Instruction separation. Variable scope. The scope of a variable is the context within which it is defined. For the most part all PHP variables only have a single scope. This single scope spans included and required files as well. For example: Here the variable will be available within the included script. However, within user-defined functions a local function scope is introduced. Any variable used inside a function is by default limited to the local function scope. <? Function test(){ echo $a; /* reference to local scope variable */ } test();? This script will not produce any output because the echo statement refers to a local version of the variable, and it has not been assigned a value within this scope. The global keyword First, an example use of global: Example #1 Using global <? Function Sum(){ global $a, $b; $b = $a + $b;} Sum();echo $b;?

The above script will output 3. A second way to access variables from the global scope is to use the special PHP-defined array. Example #2 Using instead of global Using static variables <? <? <? <? PHP: extends - Manual. Basics.