[PHP] variable declaration in class

2002-06-18 Thread Jens Lehmann

Can anyone explain me why the following code causes
the parse error ... unexpected * ...  ?

class test
{
var $a = 2*10;
}

Of course I know why there's a parse error, but I don't
know the reason why PHP doesn't allow this multiplication,
although it allows a statement like e.g. var $a = 20.
I'd be thankful if anyone could enlighten me. I'm using
PHP 4.2. on Win2k.

Jens



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] variable declaration in class

2002-06-18 Thread Analysis Solutions

On Tue, Jun 18, 2002 at 07:21:51PM +0200, Jens Lehmann wrote:
 
 class test
 {
 var $a = 2*10;
 }
 
 Of course I know why there's a parse error, but I don't
 know the reason why PHP doesn't allow this multiplication,

Because, that's why. :)

--Dan

-- 
   PHP classes that make web design easier
SQL Solution  |   Layout Solution   |  Form Solution
sqlsolution.info  | layoutsolution.info |  formsolution.info
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
 4015 7 Av #4AJ, Brooklyn NY v: 718-854-0335 f: 718-854-0409

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] Variable declaration

2001-09-27 Thread Alberto

?  error_reporting(E_ALL);
 $Test=3;
 echo $Test;
?

And I get no warning about $Test not being declared before (like C
declaration).

Any1 has an example about forcing variable declaration?




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Variable declaration

2001-09-27 Thread Rasmus Lerdorf

On Thu, 27 Sep 2001, it was written:

 ?  error_reporting(E_ALL);
  $Test=3;
  echo $Test;
 ?

 And I get no warning about $Test not being declared before (like C
 declaration).

 Any1 has an example about forcing variable declaration?

What do you mean force declaration?  That's what you are doing with this
line:

  $Test = 3;

This declares $Test to be an integer with the value 3.  Assignment and
declaration is done in one step.  There is no mechanism to do it in two.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Variable declaration

2001-09-27 Thread * RzE:

 What do you mean force declaration?  That's what you are doing with this
 line:
 
   $Test = 3;

Nop! This is just starting to use a variable. Something like:

   integer $Test;

is declaring a variable. But FAFAIK it's not possible in PHP :(

-- 

* RzE:


-- 
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Variable declaration

2001-09-27 Thread Rasmus Lerdorf

  What do you mean force declaration?  That's what you are doing with this
  line:
 
$Test = 3;

 Nop! This is just starting to use a variable. Something like:

integer $Test;

 is declaring a variable. But FAFAIK it's not possible in PHP :(

Like I said, that line does both.  It sets the type internally to an
integer and assigns the value.

-Rasmus


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Variable declaration

2001-09-27 Thread Rasmus Lerdorf

That is the nature of a loosely typed scripting language.  If you prefer a
strongly typed compiled language, there are plenty of those available.

-Rasmus

On Thu, 27 Sep 2001, * RzE: wrote:

  Like I said, that line does both.  It sets the type internally to an
  integer and assigns the value.
 
  -Rasmus

 What he (Alberto) is looking for, and what I would prefer to, is to
 really explicitly declare a variable. There's a difference between a
 compiler that requires you to declare (integer $Test;) a variable
 _before_ you start using it ($Test = 3;). Ofcourse I know that PHP
 internally declares it, but it's not the same thing.

 When the compiler forces you to declare all variables you're gonna
 use it gives a better view of which variables are used in the
 script, and besides that it doesn't allow you to make any mistakes
 of using undefined variables like it does now.

 The PHP compiler doesn't really check your code intensively. You can
 use any variable without the compiler complaining. Only at the
 moment that it reaches the variable and finds out it isn't defined,
 it tells you. It would be better to explicitly have to declare the
 variable. When the compiler starts it then shouldn't execute the
 code when it contains any variable that is not explicitly declared.

 But like I said, FAFAIK explicitly declaring variables isn't
 supported by PHP :(




-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Variable declaration

2001-09-27 Thread * RzE:

 That is the nature of a loosely typed scripting language.

I know.


 If you prefer a strongly typed compiled language, there are plenty
 of those available.

I know to. But those are not as powerful for building websites as
PHP. I mean... don't get me wrong here, I think PHP is great (or
even better). It's terrific actually. I just wish sometimes that the
compiler wouldn't allow so many things. It might just be a bit more
strict. Or at least a seperate option for being more strict. Eg
something like E_EXPLICIT_DECLARE ;)

-- 

* RzE:


-- 
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Variable declaration

2001-09-27 Thread * RzE:

Original message
From: sagar N Chand [EMAIL PROTECTED]
Date: Thu, Sep 27, 2001 at 06:01:26PM +0530
Message-ID: 005101c14750$c3189b10$0101a8c0@inferno
Subject: Re: [PHP] Variable declaration

 its really a big headache with compilers like c bugging all the way just for 
declarations.
 its cl to have the freedom of using any variable at any place wherever v want in 
bet
 ween the code. chao of PHP. 
 
 /sagar

/Original message

Reply

I think it's just a matter of preference. I like this, you like
that. No harm to that. That's why I proposed the
E_EXPLICIT_DECLARATION. That way I can choose to use it, and you can
leave it for what it is. Kinda like what Perl does with use
strict;. If you don't like being forced to declare every variable
before you use it, you just don't type use strict; at the start of
your script. People like me, who do like to do that, _do_ use that
option. Everyone gets it his/her way and it bothers noone.

But anyway... I don't think they'll ever implement this, so (...)

NOTE:
PHP Rulz and this is just a small thing that doesn't change anything
to the superb power of PHP webbuilding! :)

/Reply

-- 

* RzE:


-- 
-- Renze Munnik
-- DataLink BV
--
-- E: [EMAIL PROTECTED]
-- W: +31 23 5326162
-- F: +31 23 5322144
-- M: +31 6 21811143
--
-- Stationsplein 82
-- 2011 LM  HAARLEM
-- Netherlands
--
-- http://www.datalink.nl
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Variable declaration

2001-09-26 Thread Alberto

I want PHP parser to warn/fail when I try to use a variable not declared
before. Like Option Explicit on ASP/VBA.

Thnx in advance :)



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




RE: [PHP] Variable declaration

2001-09-26 Thread Boget, Chris

 I want PHP parser to warn/fail when I try to use a variable 
 not declared before. Like Option Explicit on ASP/VBA.

Look here:

http://www.php.net/manual/en/function.error-reporting.php

Chris