TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 01-21-2008, 10:17 AM   #1 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Big Grin Is the double colon var resolution valid in an Argument?

title speaks for itself

PHP Code:
// yes yes, make the class etc etc
  
class TesterS
  
{
// Make a public constant so its open to the whole class(:S)
    
public const test "Its called a test";
    
    
// Since that value is a Constant and is set we do this, but could this be done
     
public function(self::test)
     {
     return 
self::test;
     }

// end james
  

This is well, pretty much a start where I am in Advanced Programming.. So

This is also speaking for parent::



Find the errors

James




UPDATE: oops sorry bout that >.< sorry
Orc is offline  
Reply With Quote
Old 01-21-2008, 11:34 AM   #2 (permalink)
The Frequenter
Newcomer 
 
xenon's Avatar
 
Join Date: Dec 2007
Location: Bucharest, Romania
Posts: 438
Thanks: 3
xenon is on a distinguished road
Default

Is this a joke of some sort? 'cuz I really don't get it. First of all, the big mistake is that you don't have a name for your method. Next to that, why would you want to do what you just wrote? I don't even want to know whether that is valid or not (but I'm pretty sure it isn't). I would never want to write a function that gets a variable as a parameter and returns it unchanged, but rather just use the damned variable. Especially not with a class constant or static variable, which is always available from within the class is declared, with self::const/$static.

Other than that, you're crazy
__________________
I have optimistic thoughts, even though sometimes (if not always) life's a bitch.
xenon is offline  
Reply With Quote
Old 01-21-2008, 12:19 PM   #3 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Quote:
Originally Posted by xenon View Post
Is this a joke of some sort? 'cuz I really don't get it. First of all, the big mistake is that you don't have a name for your method. Next to that, why would you want to do what you just wrote? I don't even want to know whether that is valid or not (but I'm pretty sure it isn't). I would never want to write a function that gets a variable as a parameter and returns it unchanged, but rather just use the damned variable. Especially not with a class constant or static variable, which is always available from within the class is declared, with self::const/$static.

Other than that, you're crazy
I screwed the code up cause I was in a hurry.
Orc is offline  
Reply With Quote
Old 01-21-2008, 11:58 AM   #4 (permalink)
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

The simple answer to your question is, no. Trying to use a constant of any kind (class or global) will result in a parse error, "syntax error, unexpected T_CONST, expecting T_VARIABLE". The error is pretty self-explanatory, the PHP engine expects a standard, normal, garden-variety variable (a reference or otherwise) as an argument.

If you were to try this with a static variable (public static $test = ... and self::$test as the function argument) then you would also get a parse error, this time saying: "syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM, expecting '&' or T_VARIABLE". Again it's clear that PHP really, really only wants a regular variable in there (the T_PAAMAYIM_NEKUDOTAYIM is just a constant for the '::' or T_DOUBLE_COLON operator).

If you tried to use an object property as the argument ($this->test) then I think you can guess the likely outcome from the examples given so far.

In short, you can only use a normal variable ($test) or reference (&$test) as arguments.
Salathe is offline  
Reply With Quote
The Following User Says Thank You to Salathe For This Useful Post:
Orc (01-21-2008)
Old 01-21-2008, 12:17 PM   #5 (permalink)
Orc
The Prestige
 
Orc's Avatar
 
Join Date: Dec 2007
Posts: 1,044
Thanks: 193
Orc is on a distinguished road
Default

Okay, thank you.
Orc is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 02:52 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design