NuSphere Forums Forum Index
NuSphere Forums
Reply to topic
[Fixed] Code completion for class constants.
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Hi.

This can be discussed if it is right or wrong.

But the PHP manual states this about class constants:
The value must be a constant expression, not (for example) a variable, a class member, result of a mathematical operation or a function call.

Now what is a constant expression?

Take this code.

Code:
class myFirstConstants
{
    const PHPed = 'IS COOL';
}

class mySecondConstants
{
    const PHPExpress = myFirstConstants::PHPed;
}

echo "Nusphere ";
echo mySecondConstants::PHPExpress;

If you run this code you get no errors but get the result

Nusphere IS COOL

So using a class constant from another class to declare the value of your own class constants seams to be legal in PHP.
But PHPed can't do codecompletion on the constant declaration line in the mySecondConstants. It simply does not work pressing CTRL space after you have written myFirstConstants::

Why would you want to create your own version of a perfectly valid constant.
Well the reason is that I am building a framework that uses PDO to access and manipulate data, and PDO does not have types build in for some of the most common data types.

It only supports:
PDO::PARAM_BOOL - for Boolean fields (which basicaly is an integer)
PDO::PARAM_NULL - For SQL Null
PDO::PARAM_INT - For integers
PDO::PARAM_STR - For strings and VARCHAR etc.
PDO::PARAM_LOB - FOR BLOB (LOB)
PDO::PARAM_STMT - An at the moment not supported field type by any database.

But PDO does not cover the field column type float.
So that is why I want to use the existing constants, so I can cover any future field types added to PDO by the PHP development team.

Code:
class myFieldTypes
{
   const mySTRING = PDO::PARAM_STR;
   const myINT       = PDO::PARAM_INT;
   const myFLOAT   = -1;
}

And then in the code I can write this

Code:
function bindParam($fieldname, @$bindVariable, $fieldType)
{
   $placeholder = ':' . $fieldname;
   if ($fieldType > 0)
      $statement->bindParam($placeHolder, @$bindVariable, $fieldType);
   else
      $statement->bindParam($placeHolder, @$bindVariable);
}

And when PDO gets updated to include the Float column type, all I have to alter is the constant in myFieldTypes

Hope you see the picture.
A. As long as it is a constant expression it is valid to create a class constant with another constant value
B. Code completion does not work if you do that.

Pheww long forum post Very Happy
View user's profileFind all posts by hgrSend private message
Site Admin

Joined: 13 Jul 2003
Posts: 8344
Reply with quote
Thanks for your report. We've fixed Code Completion in build 5225 and it will be available in the next few days:

_________________
The PHP IDE team
View user's profileFind all posts by dmitriSend private messageVisit poster's website
Veteran

Joined: 30 Nov 2006
Posts: 186
Reply with quote
Great. Thank you.
View user's profileFind all posts by hgrSend private message
[Fixed] Code completion for class constants.
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
All times are GMT - 5 Hours  
Page 1 of 1  

  
  
 Reply to topic