PHP5 Instruction SELF::

 
Post new topic   Reply to topic    Aprelium Forum Index -> PHP
View previous topic :: View next topic  
Author Message
egoo
-


Joined: 22 Jan 2008
Posts: 16

PostPosted: Tue Jan 22, 2008 6:40 pm    Post subject: PHP5 Instruction SELF:: Reply with quote

class MyColorEnumClass{

const RED = "Red";
const GREEN = "Green";
const BLUE = "Blue" ;

function printBlue()
{
print self::BLUE;
}
}

print MyColorEnumClass::RED;
$obj = new MyColorEnumClass();

When I 'm running this script it prints only "Red", provided it have to print
"Red" and "Blue". I use PHPDesigner 2007 Professional. There are a FILE option which is situated between optrions REPLACE and PROJECT in the toolbar. When I click File>JUMP TO DECLARATION there the instruction SELF:: DOES NOT APPEAR. But I don't know what I have to do. Please , help me. Thank you in advance.:)
Back to top View user's profile Send private message
pkSML
-


Joined: 29 May 2006
Posts: 952
Location: Michigan, USA

PostPosted: Tue Jan 22, 2008 11:07 pm    Post subject: Reply with quote

This PHP is a little over my head, but it seems you never call the printBlue() function. Might this be why it doesn't do anything???
_________________
Stephen
Need a LitlURL?


http://CodeBin.yi.org
Back to top View user's profile Send private message Visit poster's website
roganty
-


Joined: 08 Jun 2004
Posts: 357
Location: Bristol, UK

PostPosted: Wed Jan 23, 2008 12:29 am    Post subject: Re: PHP5 Instruction SELF:: Reply with quote

As pkSML pointed out you are not calling the printBlue() function
The following code should work.
Code:
class MyColorEnumClass{
   
   const RED = "Red";
   const GREEN = "Green";
   const BLUE = "Blue" ;
   
   function printBlue()
   {
   print self::BLUE;
   }
}

print MyColorEnumClass::RED;
$obj = new MyColorEnumClass();
[b]$obj->printBlue();[/b] //Added

_________________
Anthony R

Roganty
| Links-Links.co.uk
Back to top View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Aprelium Forum Index -> PHP All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB phpBB Group