maxudaskin Posted August 6, 2008 Share Posted August 6, 2008 I just want to confirm my ever expanding knowledge of Classes. $this refers to the class that it is in? Any function in an extension class that has the same name as one in the parent class will overwrite (so to speak) the parent function To call an overwritten function, you have to write parent::functionName(); Anytime you have a function named __construct it will automatically run, unless an extension of that class has __construct. In that case, the extension will have to call parent::_construct(); to allow the parent's constructor to run. className::functionName(); will only run the function if $this is not involved. $class = new className; $class->functionName(); will run if $this is used or if it is not used. Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Correct. Any time that you want to refer to the entire class as a whole in a statically called function, you need to use self::$variable or whatever the variable is called. Anything else? Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted August 6, 2008 Author Share Posted August 6, 2008 What is Public, Private and any other attributes to the functions and variables? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Public, protected and private are all visibility indicators of class properties and methods. They basically dictate what can access them. Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted August 6, 2008 Author Share Posted August 6, 2008 And when does a deconstructor come into play? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 It's called a destructor. It follows the same naming convention as a constructor: public function __destruct() { } And PHP calls it when an instance of a class is destroyed. It's used for any last minute cleanup of connections and resources and stuff. It gets called for instance, when you do unset($your_object); Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted August 6, 2008 Author Share Posted August 6, 2008 What does a single & mean in PHP? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 Where? In a function call, it's an instruction to pass by reference. In most other things, it's the bitwise operator AND. Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted August 6, 2008 Author Share Posted August 6, 2008 What do you mean to pass by reference? What is it referencing? class loginHTML { function loginpage ( &$params, $image ) { // This Line <?php /** * @version $Id: login.html.php 10002 2008-02-08 10:56:57Z willebil $ * @package Joomla * @subpackage Users * @copyright Copyright (C) 2005 Open Source Matters. All rights reserved. * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php * Joomla! is free software. This version may have been modified pursuant * to the GNU General Public License, and as distributed it includes or * is derivative of works licensed under the GNU General Public License or * other free or open source software licenses. * See COPYRIGHT.php for copyright notices and details. */ // no direct access defined( '_VALID_MOS' ) or die( 'Restricted access' ); /** * @package Joomla * @subpackage Users */ class loginHTML { function loginpage ( &$params, $image ) { // This Line global $mosConfig_lang; // used for spoof hardening $validate = josSpoofValue(1); $return = $params->get('login'); ?> <form action="<?php echo sefRelToAbs( 'index.php?option=login' ); ?>" method="post" name="login" id="login"> <table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" class="contentpane<?php echo $params->get( 'pageclass_sfx' ); ?>"> <tr> <td colspan="2"> <?php if ( $params->get( 'page_title' ) ) { ?> <div class="componentheading<?php echo $params->get( 'pageclass_sfx' ); ?>"> <?php echo $params->get( 'header_login' ); ?> </div> <?php } ?> <div> <?php echo $image; ?> <?php if ( $params->get( 'description_login' ) ) { ?> <?php echo $params->get( 'description_login_text' ); ?> <br/><br/> <?php } ?> </div> </td> </tr> <tr> <td align="center" width="50%"> <br /> <table> <tr> <td align="center"> <?php echo _USERNAME; ?> <br /> </td> <td align="center"> <?php echo _PASSWORD; ?> <br /> </td> </tr> <tr> <td align="center"> <input name="username" type="text" class="inputbox" size="20" /> </td> <td align="center"> <input name="passwd" type="password" class="inputbox" size="20" /> </td> </tr> <tr> <td align="center" colspan="2"> <br/> <?php echo _REMEMBER_ME; ?> <input type="checkbox" name="remember" class="inputbox" value="yes" /> <br/> <a href="<?php echo sefRelToAbs( 'index.php?option=com_registration&task=lostPassword' ); ?>"> <?php echo _LOST_PASSWORD; ?> </a> <?php if ( $params->get( 'registration' ) ) { ?> <br/> <?php echo _NO_ACCOUNT; ?> <a href="<?php echo sefRelToAbs( 'index.php?option=com_registration&task=register' ); ?>"> <?php echo _CREATE_ACCOUNT;?> </a> <?php } ?> <br/><br/><br/> </td> </tr> </table> </td> <td> <div align="center"> <input type="submit" name="submit" class="button" value="<?php echo _BUTTON_LOGIN; ?>" /> </div> </td> </tr> <tr> <td colspan="2"> <noscript> <?php echo _CMN_JAVASCRIPT; ?> </noscript> </td> </tr> </table> <?php // displays back button mosHTML::BackButton ( $params ); ?> <input type="hidden" name="op2" value="login" /> <input type="hidden" name="return" value="<?php echo sefRelToAbs( $return ); ?>" /> <input type="hidden" name="lang" value="<?php echo $mosConfig_lang; ?>" /> <input type="hidden" name="message" value="<?php echo $params->get( 'login_message' ); ?>" /> <input type="hidden" name="<?php echo $validate; ?>" value="1" /> </form> <?php } function logoutpage( &$params, $image ) { global $mosConfig_lang; $return = $params->get('logout'); ?> <form action="<?php echo sefRelToAbs( 'index.php?option=logout' ); ?>" method="post" name="login" id="login"> <table width="100%" border="0" align="center" cellpadding="4" cellspacing="0" class="contentpane<?php echo $params->get( 'pageclass_sfx' ); ?>"> <tr> <td valign="top"> <?php if ( $params->get( 'page_title' ) ) { ?> <div class="componentheading<?php echo $params->get( 'pageclass_sfx' ); ?>"> <?php echo $params->get( 'header_logout' ); ?> </div> <?php } ?> <div> <?php echo $image; if ( $params->get( 'description_logout' ) ) { echo $params->get( 'description_logout_text' ); ?> <br/><br/> <?php } ?> </div> </td> </tr> <tr> <td align="center"> <div align="center"> <input type="submit" name="Submit" class="button" value="<?php echo _BUTTON_LOGOUT; ?>" /> </div> </td> </tr> </table> <?php // displays back button mosHTML::BackButton ( $params ); ?> <input type="hidden" name="op2" value="logout" /> <input type="hidden" name="return" value="<?php echo sefRelToAbs( $return ); ?>" /> <input type="hidden" name="lang" value="<?php echo $mosConfig_lang; ?>" /> <input type="hidden" name="message" value="<?php echo $params->get( 'logout_message' ); ?>" /> </form> <?php } } ?> Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 6, 2008 Share Posted August 6, 2008 First of all, that's a rather ugly class and I don't like it, but whatever. Okay. Now...how to explain this...Well, first some code and what it does, then WHY it does that. Let's say you had: function add15($var) { $var += 15; } $var = 10; add15($var); echo $var; //echos 10 But now, if you had: function add15(&$var) { $var += 15; } $var = 10; add15($var); echo $var; //echos 15 This is because normally, when you pass something to a function, it's passed by value and then the function makes copies of it in local variables. When you pass by reference, it passes the variable by the location in memory and then any changes to the variable directly affects the variable passed into the function. Sort of like pointers in C and C++, but not exactly the same. Quote Link to comment Share on other sites More sharing options...
maxudaskin Posted August 7, 2008 Author Share Posted August 7, 2008 Oh... ok. Without the &, the function makes a copy of the variable and then manipulates it. With the &, the function accesses the variable directly and manipulates it directly. Did I get you right? Quote Link to comment Share on other sites More sharing options...
DarkWater Posted August 7, 2008 Share Posted August 7, 2008 Yup. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.