Define variables with a type

Define variables with a type

am 01.11.2007 13:08:18 von Phillip Taylor

I've been looking on the Internet and I can't seem to see any one
specifying a variable with a type. Will someone please tell me it can
be done.

int $tablename = 0;

rather than

var $tablename = 0;

Is it possible?

If not, do you all go back to using hungarian notation in order to
know what data types your working so you don't accidently set false
and true against a flag which is supposed to 0 and -1?

Re: Define variables with a type

am 01.11.2007 13:11:16 von Jerry Stuckle

Philluminati wrote:
> I've been looking on the Internet and I can't seem to see any one
> specifying a variable with a type. Will someone please tell me it can
> be done.
>
> int $tablename = 0;
>
> rather than
>
> var $tablename = 0;
>
> Is it possible?
>
> If not, do you all go back to using hungarian notation in order to
> know what data types your working so you don't accidently set false
> and true against a flag which is supposed to 0 and -1?
>
>

No, PHP variables are untyped.

And no, I don't use Hungarian notation. Rather, I document the code.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Define variables with a type

am 01.11.2007 13:15:13 von Phillip Taylor

On Nov 1, 12:11 pm, Jerry Stuckle wrote:
> Philluminati wrote:
> > I've been looking on the Internet and I can't seem to see any one
> > specifying a variable with a type. Will someone please tell me it can
> > be done.
>
> > int $tablename = 0;
>
> > rather than
>
> > var $tablename = 0;
>
> > Is it possible?
>
> > If not, do you all go back to using hungarian notation in order to
> > know what data types your working so you don't accidently set false
> > and true against a flag which is supposed to 0 and -1?
>
> No, PHP variables are untyped.
>
> And no, I don't use Hungarian notation. Rather, I document the code.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

How do you document the code if I may ask? with #comments around the
variable? Do you then have to go traipsing through the .php files to
find it's original meaning? I think this was the original reason for
Hungarian notation. Now I might just be dinosaur but is it much of a
problem or do you learn to get along fine without types?

Re: Define variables with a type

am 01.11.2007 13:20:36 von Jerry Stuckle

Philluminati wrote:
> On Nov 1, 12:11 pm, Jerry Stuckle wrote:
>> Philluminati wrote:
>>> I've been looking on the Internet and I can't seem to see any one
>>> specifying a variable with a type. Will someone please tell me it can
>>> be done.
>>> int $tablename = 0;
>>> rather than
>>> var $tablename = 0;
>>> Is it possible?
>>> If not, do you all go back to using hungarian notation in order to
>>> know what data types your working so you don't accidently set false
>>> and true against a flag which is supposed to 0 and -1?
>> No, PHP variables are untyped.
>>
>> And no, I don't use Hungarian notation. Rather, I document the code.
>>
>
> How do you document the code if I may ask? with #comments around the
> variable? Do you then have to go traipsing through the .php files to
> find it's original meaning? I think this was the original reason for
> Hungarian notation. Now I might just be dinosaur but is it much of a
> problem or do you learn to get along fine without types?
>
>

I comment the code as necessary - but I use /* ... */ and // - PHP
doesn't recognize # as a comment delimiter.

And no, I don't have to search through multiple files. My variables
aren't found in more than one file. I structure my code.

And in any case, sometimes my code might contain false, while at other
times it might contain -1 or 0. And they would have different meanings.

For instance, a database request might return a resource object or false
- depending on whether the request was set or not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Define variables with a type

am 01.11.2007 15:38:59 von zdzisio

Philluminati pisze:

> int $tablename = 0;
>
> rather than
>
> var $tablename = 0;
>
> Is it possible?

no .
of course you can do something like

public $tablename = (int)0;

but this does not prevent asigning value of a different type to that
variable.

that's the way it is

> If not, do you all go back to using hungarian notation in order to
> know what data types your working

I do

z.

Re: Define variables with a type

am 01.11.2007 15:48:07 von luiheidsgoeroe

On Thu, 01 Nov 2007 13:15:13 +0100, Philluminati =

wrote:

> On Nov 1, 12:11 pm, Jerry Stuckle wrote:
>> Philluminati wrote:
>> > I've been looking on the Internet and I can't seem to see any one
>> > specifying a variable with a type. Will someone please tell me it c=
an
>> > be done.
>>
>> > int $tablename =3D 0;
>>
>> > rather than
>>
>> > var $tablename =3D 0;
>>
>> > Is it possible?
>>
>> > If not, do you all go back to using hungarian notation in order to
>> > know what data types your working so you don't accidently set false=

>> > and true against a flag which is supposed to 0 and -1?
>>
>> No, PHP variables are untyped.
>>
>> And no, I don't use Hungarian notation. Rather, I document the code.=

>>
>
> How do you document the code if I may ask? with #comments around the
> variable? Do you then have to go traipsing through the .php files to
> find it's original meaning?

Normally, I use phpDocumentor.... Comments inline, generate documentatio=
n =

from them on changes. http://www.phpdoc.org

> I think this was the original reason for
> Hungarian notation. Now I might just be dinosaur but is it much of a
> problem or do you learn to get along fine without types?

PHP's advantage and disadvantage is variable types. One learns to deal =

with it with either loose matching, or casting/strict comparisons. In =

class methods starting with PHP 5 you can specify an argument has to be =
=

(derived from) a particular object, that's about it.
-- =

Rik Wasmus

Re: Define variables with a type

am 01.11.2007 17:12:55 von colin.mckinnon

On 1 Nov, 12:08, Philluminati wrote:
> I've been looking on the Internet and I can't seem to see any one
> specifying a variable with a type. Will someone please tell me it can
> be done.
>
> int $tablename = 0;
>
> rather than
>
> var $tablename = 0;
>
> Is it possible?

No - but if you can't understand dynamic typing and think strong
typing will help, look at PHPLint.

>
> If not, do you all go back to using hungarian notation in order to
> know what data types your working so you don't accidently set false
> and true against a flag which is supposed to 0 and -1?

No. I found out how dynamic typing worked and learned to use it
effectively.

C.

Re: Define variables with a type

am 01.11.2007 18:52:55 von Michael Fesser

..oO(Rik Wasmus)

>On Thu, 01 Nov 2007 13:15:13 +0100, Philluminati
> wrote:
>
>> How do you document the code if I may ask? with #comments around the
>> variable? Do you then have to go traipsing through the .php files to
>> find it's original meaning?
>
>Normally, I use phpDocumentor.... Comments inline, generate documentation
> from them on changes. http://www.phpdoc.org

These comments and their special tags can also be used by IDEs like
Eclipse for "IntelliSense" code hints.

>> I think this was the original reason for
>> Hungarian notation. Now I might just be dinosaur but is it much of a
>> problem or do you learn to get along fine without types?
>
>PHP's advantage and disadvantage is variable types. One learns to deal
>with it with either loose matching, or casting/strict comparisons. In
>class methods starting with PHP 5 you can specify an argument has to be
>(derived from) a particular object, that's about it.

It also works for arrays.

Micha

Re: Define variables with a type

am 01.11.2007 20:04:48 von Shelly

C. (http://symcbean.blogspot.com/) wrote:
> On 1 Nov, 12:08, Philluminati wrote:
>> I've been looking on the Internet and I can't seem to see any one
>> specifying a variable with a type. Will someone please tell me it can
>> be done.
>>
>> int $tablename = 0;
>>
>> rather than
>>
>> var $tablename = 0;
>>
>> Is it possible?
>
> No - but if you can't understand dynamic typing and think strong
> typing will help, look at PHPLint.

PHP 5 has type hinting. That's close.

--
Shelly

Re: Define variables with a type

am 02.11.2007 00:01:55 von Norman Peelman

Philluminati wrote:
> I've been looking on the Internet and I can't seem to see any one
> specifying a variable with a type. Will someone please tell me it can
> be done.
>
> int $tablename = 0;
>
> rather than
>
> var $tablename = 0;
>
> Is it possible?
>
> If not, do you all go back to using hungarian notation in order to
> know what data types your working so you don't accidently set false
> and true against a flag which is supposed to 0 and -1?
>

You could name your variables to match the data you expect them to
hold, for instance:

$bTemp --> boolean
$sTemp --> string
$iTemp --> integer
$fTemp --> float

....it may help you visually.

Norm

Re: Define variables with a type

am 02.11.2007 02:51:59 von Jerry Stuckle

Norman Peelman wrote:
> Philluminati wrote:
>> I've been looking on the Internet and I can't seem to see any one
>> specifying a variable with a type. Will someone please tell me it can
>> be done.
>>
>> int $tablename = 0;
>>
>> rather than
>>
>> var $tablename = 0;
>>
>> Is it possible?
>>
>> If not, do you all go back to using hungarian notation in order to
>> know what data types your working so you don't accidently set false
>> and true against a flag which is supposed to 0 and -1?
>>
>
> You could name your variables to match the data you expect them to
> hold, for instance:
>
> $bTemp --> boolean
> $sTemp --> string
> $iTemp --> integer
> $fTemp --> float
>
> ...it may help you visually.
>
> Norm
>

Which is Hungarian notation - and something most of us don't use in PHP.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Define variables with a type

am 02.11.2007 02:57:21 von luiheidsgoeroe

On Fri, 02 Nov 2007 02:51:59 +0100, Jerry Stuckle =

wrote:

> Norman Peelman wrote:
>> Philluminati wrote:
>>> I've been looking on the Internet and I can't seem to see any one
>>> specifying a variable with a type. Will someone please tell me it ca=
n
>>> be done.
>>>
>>> int $tablename =3D 0;
>>>
>>> rather than
>>>
>>> var $tablename =3D 0;
>>>
>>> Is it possible?
>>>
>>> If not, do you all go back to using hungarian notation in order to
>>> know what data types your working so you don't accidently set false
>>> and true against a flag which is supposed to 0 and -1?
>>>
>> You could name your variables to match the data you expect them to=
=

>> hold, for instance:
>> $bTemp --> boolean
>> $sTemp --> string
>> $iTemp --> integer
>> $fTemp --> float
>> ...it may help you visually.
>> Norm
>>
>
> Which is Hungarian notation - and something most of us don't use in PH=
P.
>

Hmm, maybe a deviation here, I see this more often then not..
-- =

Rik Wasmus

Re: Define variables with a type

am 02.11.2007 03:33:56 von Jerry Stuckle

Rik Wasmus wrote:
> On Fri, 02 Nov 2007 02:51:59 +0100, Jerry Stuckle
> wrote:
>
>> Norman Peelman wrote:
>>> Philluminati wrote:
>>>> I've been looking on the Internet and I can't seem to see any one
>>>> specifying a variable with a type. Will someone please tell me it can
>>>> be done.
>>>>
>>>> int $tablename = 0;
>>>>
>>>> rather than
>>>>
>>>> var $tablename = 0;
>>>>
>>>> Is it possible?
>>>>
>>>> If not, do you all go back to using hungarian notation in order to
>>>> know what data types your working so you don't accidently set false
>>>> and true against a flag which is supposed to 0 and -1?
>>>>
>>> You could name your variables to match the data you expect them to
>>> hold, for instance:
>>> $bTemp --> boolean
>>> $sTemp --> string
>>> $iTemp --> integer
>>> $fTemp --> float
>>> ...it may help you visually.
>>> Norm
>>>
>>
>> Which is Hungarian notation - and something most of us don't use in PHP.
>>
>
> Hmm, maybe a deviation here, I see this more often then not..

Hi, Rik,

I see it very seldom on untyped languages such as PHP. It is, however,
quite common in languages like C and PASCAL - although it seems to
becoming less common there, also (IMHE, of course).

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================

Re: Define variables with a type

am 04.11.2007 23:18:09 von Norman Peelman

Jerry Stuckle wrote:
> Rik Wasmus wrote:
>> On Fri, 02 Nov 2007 02:51:59 +0100, Jerry Stuckle
>> wrote:
>>
>>> Norman Peelman wrote:
>>>> Philluminati wrote:
>>>>> I've been looking on the Internet and I can't seem to see any one
>>>>> specifying a variable with a type. Will someone please tell me it can
>>>>> be done.
>>>>>
>>>>> int $tablename = 0;
>>>>>
>>>>> rather than
>>>>>
>>>>> var $tablename = 0;
>>>>>
>>>>> Is it possible?
>>>>>
>>>>> If not, do you all go back to using hungarian notation in order to
>>>>> know what data types your working so you don't accidently set false
>>>>> and true against a flag which is supposed to 0 and -1?
>>>>>
>>>> You could name your variables to match the data you expect them
>>>> to hold, for instance:
>>>> $bTemp --> boolean
>>>> $sTemp --> string
>>>> $iTemp --> integer
>>>> $fTemp --> float
>>>> ...it may help you visually.
>>>> Norm
>>>>
>>>
>>> Which is Hungarian notation - and something most of us don't use in PHP.
>>>
>>
>> Hmm, maybe a deviation here, I see this more often then not..
>
> Hi, Rik,
>
> I see it very seldom on untyped languages such as PHP. It is, however,
> quite common in languages like C and PASCAL - although it seems to
> becoming less common there, also (IMHE, of course).
>

I never knew it had a specific name. I happened to notice it used in
scripting games like Unreal Tournament (which I know is C code and so
now it all makes sense).

Norm