Jump to content

SystemOverload

Members
  • Posts

    28
  • Joined

  • Last visited

    Never

Everything posted by SystemOverload

  1. So why were the properties assigned values in the example where the child had no constructor???
  2. Thorpe Thanks, but why were there parent's variables available in the normal methods, but not the constructor. Without the parent::__constructor() was 'echo $this->protected;' effectively redeclaring it (and consequentially setting it's value to nothing) in the child object?
  3. JC, you can, because in both examples I am accessing properties from the parent object, just in the second example I try to access those from the child's constructor first, which seems to erase the contents in the child. ???
  4. I'm doing some basic object coding to get my head around OOP PHP, but I've come across something I can't get to work. I've got two identical peices of code, MyClass is defined, MyClass2 is then defined as an extension of MyClass. MyClass has three properties Public, Private and Protected. In my first example I can access Public and Protected via a method in MyClass2, this class does NOT have a constructor. The second example has a constructor but I cannot access Public: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <body> <?php ECHO "MyClass2 does not have a constructor, Public & Protected both echo correctly from MyClass2->printHello!!!<BR>"; /** * Define MyClass */ class MyClass { public $public; protected $protected; private $private; protected $varXXX; function __construct() { $this->public = "Public"; $this->protected = "Protected"; $this->private = "Private"; //$this->printHello(); } function printHello() { echo $this->public . "!!!<BR>"; echo $this->protected . "!!!<BR>"; echo $this->private . "!!!<BR>"; } } /** * Define MyClass2 */ class MyClass2 extends MyClass { // We can redeclare the public and protected method, but not private protected $protected = 'Protected2'; /* function __construct() { echo $this->public . "#<BR>"; echo $this->protected . "#<BR><BR>"; //echo $this->private . "???<BR>"; } */ function printHello() { echo $this->public . "???<BR>"; echo $this->protected . "???<BR><BR>"; //echo $this->private . "???<BR>"; } } $obj = new MyClass(); //echo $obj->public . "<BR>"; // Works //echo $obj->protected; // Fatal Error //echo $obj->private; // Fatal Error //$obj->printHello(); // Shows Public, Protected and Private $obj2 = new MyClass2(); //echo $obj2->public; // Works //echo $obj2->private; // Undefined //echo $obj2->protected; // Fatal Error $obj2->printHello(); // Shows Public, Protected2, Undefined ?> </body> </html> RESULTS IN: Public??? Protected??? <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <body> <?php ECHO "MyClass2 DOES have a constructor, Public does not work from MyClass2->printHello!!!<BR>"; /** * Define MyClass */ class MyClass { public $public; protected $protected; private $private; protected $varXXX; function __construct() { $this->public = "Public"; $this->protected = "Protected"; $this->private = "Private"; //$this->printHello(); } function printHello() { echo $this->public . "!!!<BR>"; echo $this->protected . "!!!<BR>"; echo $this->private . "!!!<BR>"; } } /** * Define MyClass2 */ class MyClass2 extends MyClass { // We can redeclare the public and protected method, but not private protected $protected = 'Protected2'; function __construct() { echo $this->public . "#<BR>"; echo $this->protected . "#<BR><BR>"; //echo $this->private . "???<BR>"; } function printHello() { echo $this->public . "???<BR>"; echo $this->protected . "???<BR><BR>"; //echo $this->private . "???<BR>"; } } $obj = new MyClass(); //echo $obj->public . "<BR>"; // Works //echo $obj->protected; // Fatal Error //echo $obj->private; // Fatal Error //$obj->printHello(); // Shows Public, Protected and Private $obj2 = new MyClass2(); //echo $obj2->public; // Works //echo $obj2->private; // Undefined //echo $obj2->protected; // Fatal Error $obj2->printHello(); // Shows Public, Protected2, Undefined ?> </body> </html> RESULTS IN: # << Missing the property's contents Protected2# ??? << Missing the property's contents Protected2??? Any ideas why I cannot access the property's contents in the second example when the only difference is that it has a constructor?
  5. 1 and 2 didn't seem to work and I didn't like the look of 3, so steered clear. I went with extending ClassB from ClassA. Instantiated ClassB, which had a constructor that called ClassA's constructor. This then allowed me to call ClassA's variable from inside CLassB as "$this->variable".
  6. Apologies, I thought I'd been quite clear in my question. Let me layout exactly what I want to know is possible or not: class clClassA { public varA; function clClassA { ...blah... $this->varA = 999; ...blah... } function fnFunctionA { <does something else> } } class clClassB { function clClassB { echo $objA::varA; } } objA = new clClassA; objB = new clClassB; I want objB to be able to access objA::varA or execute objA::fnFunctionA IE: access one class' properties/methods from within another class' methods. I do not want to instigate things or access properties from outside of the classes. Is my question clearer now? Thnx
  7. Thanks, but that didn't help. The properties are public, or at least some are, but the object is not recognised: Notice: Undefined variable: objSession in C:\WEBSERVER\system\classes\clAccount.class on line 9 Notice: Trying to get property of non-object in C:\WEBSERVER\system\classes\clAccount.class on line 9 Can you give me a yes/no? Should I be able to access Class A's properties and methods from Class B's methods?
  8. Hi Can you call Class A's methods or properties from Class B's methods? Thanks.
  9. ok, thanks for everyone's input, especially the last guy, upto the point where he posted, I didn't get exactly what i asked for... If you read my original request: Everyone except the last guy dropped titbits, but didn't give me exactly what I needed, finally I finished up with the following: (credit for the substr() bit goes to a random tutorial I found thru google) $varQuery = ""; if (strlen($_SERVER['QUERY_STRING']) != 0) {$varQuery = "?";} $varURL = substr($_SERVER['SERVER_PROTOCOL'],0,strpos($_SERVER['SERVER_PROTOCOL'],'/')) . "://" . $_SERVER["HTTP_HOST"] . $_SERVER['SCRIPT_NAME'] . $varQuery . $_SERVER['QUERY_STRING'] ; Thanks for everyones help.
  10. Trouble is _SERVER is an array and parse_url takes a string... How do i get from _SERVER to "http://www.domain.com/dir1/dir2/something.php?id=1&mode=pwc" Sorry for being a pain, lol Thanks
  11. I'm sorry, I didn't make myself clear. How do I retrieve the seperate parts of the url, parse_url() is just a function, how do I get the URL itself into a variable so I can start manipulating it? Thanks
  12. PHP 5.2.5 I want to create a function to manipulate the current URL. How is the best way to retrieve the separate parts of the URL to a variable. 1 - "HTTP" or "HTTPS" etc 2 - www.domain.com 3 - directory/2nddirectory 4 - index.php 5 - id=10&mode=qv I want to be able to insert and/or remove 'variables' to facilitate passing more information thru _GET Thanks
  13. I've started with the basic mail(), quickly finding it doesn't provide much feedback in case of errors, such as the mail server is offline/not responding... I now need a function/class which allows me to specify a domain/ip as the mailserver and one which if it can't talk to the server, gives me the chance to provide a dignified error message back to the user etc... Any ideas guys? Thanks
  14. Hey I'm on PHP 5.3.4ish. I've recently started using PHPMailer, but when testing it, end up with an "Could not instantiate mail function." error. Does anyone have any ideas? My files are laid out as below: /emailtest.php - Calls fn_mailer("test@live.co.uk","Test Email Recipient","Subject","BODY") /includes/functions/fn_comms.php - Contains function fn_mailer(), a simple wrapper that accesses the PHPMailer Functionality... /includes/functions/phpmailer/class.phpmailer.php /includes/functions/phpmailer/class.pop3.php /includes/functions/phpmailer/class.smtp.php fn_mailer() function fnMailer ($varToEmail, $varToName, $varSubject, $varBody) { // - -- --- Wrapper for PHP Mailer Class Interface ------------------------------------ require_once 'phpmailer/class.phpmailer.php'; $mail = new PHPMailer(true); //defaults to using php "mail()"; the true param means it will throw exceptions on errors, which we need to catch try { $mail->AddReplyTo('support@test.info', 'Support'); $mail->AddAddress($varToEmail, $varToName); $mail->SetFrom('donotreply@test.info', 'Admin'); $mail->Subject = $varSubject; $mail->AltBody = 'To view this email message, please use an HTML compatible email viewer!'; // optional - MsgHTML will create an alternate automatically //$mail->MsgHTML(file_get_contents('contents.html')); $mail->MsgHTML($varBody); //$mail->AddAttachment('images/phpmailer.gif'); // attachment //$mail->AddAttachment('images/phpmailer_mini.gif'); // attachment $mail->Send(); echo "Message Sent OK</p>\n"; } catch (phpmailerException $e) { echo $e->errorMessage(); //Pretty error messages from PHPMailer } catch (Exception $e) { echo $e->getMessage(); //Boring error messages from anything else! } // - -- --- END OF WRAPPER ------------------------------------------------------------------ }
  15. Ignore my previous ignorance, you were totally right I just wasn't thinking about the problem in the right way... UPDATE tbl_listings SET c_password_reset_code = 'afe915b81e02df723a1df0ee3e70a75e', c_password_reset_valid_to =NOW() + INTERVAL 24 HOUR WHERE contact_email = 'someone@live.co.uk' Thank you
  16. because it's not an event I can trigger, so how do i do it in PHP, ensuring it's formatted ready for mysql?
  17. PHP 5.2.6 Hi.. I need to insert a time into an MySQL DB. It needs to be done by the php, as opposed to the database doing the maths... What is the best way to insert a "now + 24 hrs" etc into a db, I just need the value, not the SQL Statement.. Thanks
  18. Well I've done the code for a basic html email, now I want to create an email with plain text and html, for maximum compatability... I was recommended to find a class etc.. but i want to do it from scratch.. The email is sending, but when i view it in windows live (a live co uk email), it's blank... Can anyone shine a light on this??? My PHP is: $semi_rand = md5(time()); $varBoundary = "==Multipart_Boundary_x{$semi_rand}x"; $vTo = $varTo; $vSubject = $varSubject; $varMessage = wordwrap($varMessage); $varMessagePlus = wordwrap($varMessagePlus); $varHeaders = "From: donotreply@somewhere.info" . "\n"; $varHeaders .= "Reply-To: support@somewhere.info" . "\n"; $varHeaders .= "MIME-Version: 1.0\n"; $varHeaders .= "Content-type: multipart/alternative; boundary=\"{$varBoundary}\"" . "\n"; $vHeaders = $varHeaders; $vMessage = "This is a multipart message in MIME format." . "\n" . "\r\n\r\n--" . $varBoundary . "\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"" . "\n" . "Content-Transfer-Encoding: 7bit" . "\n" . $varMessage . "\r\n\r\n--" . $varBoundary . "\n" . "Content-Type: text/html; charset=\"iso-8859-1\"" . "\n" . "Content-Transfer-Encoding: 7bit" . "\n" . $varMessagePlus . "\r\n\r\n--" . $varBoundary . "--"; if (@mail($vTo, $vSubject, $vMessage, $vHeaders) or die()) { return 0; } else { return 1; } The source for the resultant email is: X-Message-Delivery: Vj0xLjE7dXM9MDtsPTA7YT0xO0Q9MTtTQ0w9Mw== X-Message-Status: n:0 X-SID-PRA: donotreply@locateme.info X-Message-Info: JGTYoYF78jFo0fMWAWRa/U5XMCnQ9sKUucqF/OgvT0eS7L/cF/OPgKbB0TbyCsdQYQtaYfzda/MRBCOZcNyK3nxKrmuiOELU Received: from WebServer1.DNPwebhosting.com ([213.175.208.2]) by SNT0-MC3-F38.Snt0.hotmail.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 9 Sep 2009 13:06:17 -0700 Received: from WebServer1 ([127.0.0.1]) by WebServer1.DNPwebhosting.com with Microsoft SMTPSVC(6.0.3790.3959); Wed, 9 Sep 2009 21:06:54 +0100 Date: Wed, 09 Sep 2009 21:06:54 +0100 Subject: Test Message To: system.overload@live.co.uk From: donotreply@locateme.info Reply-To: support@locateme.info MIME-Version: 1.0 Content-type: multipart/alternative; boundary="==Multipart_Boundary_x020feb40747da5aca2aa8dccc9fd3050x" Return-Path: donotreply@locateme.info Message-ID: <WEBSERVER1Aq9KP8RlR00000021@WebServer1.DNPwebhosting.com> X-OriginalArrivalTime: 09 Sep 2009 20:06:54.0233 (UTC) FILETIME=[13959090:01CA3189] This is a multipart message in MIME format. --==Multipart_Boundary_x020feb40747da5aca2aa8dccc9fd3050x Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit This is a plain text message... --==Multipart_Boundary_x020feb40747da5aca2aa8dccc9fd3050x Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: 7bit <html> <body> <h1>This is the HTML Message</h1> <p>With some more text...</p> </body> </html> --==Multipart_Boundary_x020feb40747da5aca2aa8dccc9fd3050x--
  19. Thanks, I managed to get it working, I'm looking at the combined HTML / Plain Text version now LOL... I've picked out the following from the message: --==Multipart_Boundary_xc75j85x Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Is the Content-Transfer-Encoding required? And what is it's recommended 'setting' for HTML and for Plain Text as I've seen a number of different variations Thanks
  20. Hi, I'm using PHP 5.2.6 and I need to send automatic emails to help users reset their passwords... I've received the email ok, but it displays the html, tags and all... Can anyone point me in the right direction to get it to display correctly? X-Message-Delivery: Vj0xLjE7dXM9MDtsPTA7YT0xO0Q9MTtTQ0w9Mw== X-Message-Status: n:0 X-SID-PRA: donotreplyATsomethingDOTcom X-Message-Info: JGTYoYF78jHqxCLOcGSmIalZsSnmX77i+0RJd3fM2tipTgPAv4DzSwwDAS9CLMZize0xQmoU6xgKXEmqN4kZmD40Qw+lF92P Received: from WebServer1.DNPwebhostingDOTcom ([213.175.208.2]) by snt0-mc2-f22.Snt0.hotmailDOTcom with Microsoft SMTPSVC(6.0.3790.3959); Tue, 8 Sep 2009 11:39:44 -0700 Received: from WebServer1 ([127.0.0.1]) by WebServer1.DNPwebhostingDOTcom with Microsoft SMTPSVC(6.0.3790.3959); Tue, 8 Sep 2009 19:40:20 +0100 Date: Tue, 08 Sep 2009 19:40:20 +0100 Subject: Password Reset Request... To: testATdestinationDOTcoDOTuk From: donotreplyATsomethingDOTcom Reply-To: donotreplyATsomethingDOTcom X-Mailer: PHP/5.2.6 Return-Path: donotreplyATsomethingDOTcom Message-ID: <WEBSERVER1nHM3SOlbp0000003aATWebServer1.DNPwebhostingDOTcom> X-OriginalArrivalTime: 08 Sep 2009 18:40:20.0042 (UTC) FILETIME=[D1312AA0:01CA30B3] <html> <body> <p> <a href='locateme.info/b/b_account.php?mode=options&reset=f8bd59688b7b309f865aca711e9e113f'> <b>CLICK TO RESET PASSWORD</b> </a> </p> </body> </html>
  21. LMAO - Thanks... I didn't even think about something as simple as that... Who's a moron.... >>ME<< Thank you...
  22. PHP 5.2.5 Inside a PHP function, I've returned a set of results from a table, there will only ever been one record. while ($arrAccVerify = mysql_fetch_array($rsAccVerify)) { $fldContactName = $arrAccVerify['contact_name']; return $fldContactName; } but what if I want to return a dynamic field, ie, the field of choosing at the time i call the function, ie: $varReturnField = "contact_email"; while ($arrAccVerify = mysql_fetch_array($rsAccVerify)) { $fldReturnField= $arrAccVerify['$varReturnField']; return $fldReturnField; } I tried this and i just get [Notice: Undefined index: $varReturnField]... Is what I am trying to achieve possible, and if so, how??? Thanks
  23. A - DATETIME B - Someone on another forum has provided the following solution: UNIX_TIMESTAMP() - UNIX_TIMESTAMP(orgDateAmended) AS x which appears to work just fine, unless you can see any issues with doing it this way? Thanks
  24. Ok, I get an integer (74891990) from now()-date_amended, which I presumed was seconds, but with a date of 2009-08-27 23:22:18, now()-this date should result in approx 483,304.79 seconds (8055 mins or 134 hrs or 5.59 days). If 74891990 were seconds, it would result in 866 days, ie: way out. Can someone explain why I'm getting this figure and give me a hint where I'm going wrong please. Thanks
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.