Author Topic: ospap - Alpha1  (Read 27557 times)

0 Members and 1 Guest are viewing this topic.

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: ospap - Alpha1
« Reply #105 on: October 15, 2005, 11:31:26 am »
Is there some way to make it show an error if you don't declare variables like that?

On Perl, it's "use strict;"
Use error_reporting(E_ALL); at the beginning of your core file (IE: the one that's always there, like the index.php or something).  It will throw a warning when you use a variable that isn't $_GET[], $_POST[], $_SESSION[], or my.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ospap - Alpha1
« Reply #106 on: October 15, 2005, 11:36:05 am »
There's also this entry in the php.ini file which usually (by default, on my box anyway) this:

Code: [Select]
error_reporting  = E_COMPILE_ERROR|E_ERROR|E_CORE_ERROR
Obviously, just change it to:

Code: [Select]
error_reporting = E_ALL
However, that's not going to stop your code from running, it will just display a Notice.

Offline rabbit

  • x86
  • Hero Member
  • *****
  • Posts: 8092
  • I speak for the entire clan (except Joe)
    • View Profile
Re: ospap - Alpha1
« Reply #107 on: October 15, 2005, 11:51:55 am »
Just a note: using the error_reporting() function is easier than changing the PHP hard configuration.

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ospap - Alpha1
« Reply #108 on: October 15, 2005, 11:56:19 am »
Just a note: using the error_reporting() function is easier than changing the PHP hard configuration.
Not if you want to make a global change on your server.  :P

It's easier to develop with E_ALL on in PHP.ini, then you don't have to worry about removing it when you deploy it (because people don't like error reporting in E_ALL, especially on scripts that are included as an addon or something to that affect).

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: ospap - Alpha1
« Reply #109 on: October 16, 2005, 03:54:46 pm »
Install a custom error handlers in your PHP code and treat the notices as fatal exceptions and exit your code.
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ospap - Alpha1
« Reply #110 on: October 16, 2005, 05:01:39 pm »
Install a custom error handlers in your PHP code and treat the notices as fatal exceptions and exit your code.
That would be way too much work for such a silly thing.

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: ospap - Alpha1
« Reply #111 on: October 16, 2005, 06:38:10 pm »
It's surprisingly easy but yea I think it might be overdoing it a bit. Should help for other things though too.
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ospap - Alpha1
« Reply #112 on: October 16, 2005, 10:08:33 pm »
It's surprisingly easy but yea I think it might be overdoing it a bit. Should help for other things though too.
I know, I've done it before.  There's other unseen issues that it would affect too though.  Doing it would be stupid.  It's like having a car that doesn't work if it doesn't make a sound when the driver's side door is open.  Quite useless.

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: ospap - Alpha1
« Reply #113 on: October 16, 2005, 10:16:32 pm »
You can of course filter the notice messages to the one you need :p
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ospap - Alpha1
« Reply #114 on: October 16, 2005, 10:19:04 pm »
You can of course filter the notice messages to the one you need :p
Quite useless.

: - P

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: ospap - Alpha1
« Reply #115 on: October 17, 2005, 12:07:08 am »
Don't see how it's still useless if I showed how it could be singled out into one exception and handled from there instead of making the entire thing croak becauause of every notice. (Even though IMHO it should, it enforces nice programming)

One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ospap - Alpha1
« Reply #116 on: October 17, 2005, 12:57:19 am »
Don't see how it's still useless if I showed how it could be singled out into one exception and handled from there instead of making the entire thing croak becauause of every notice. (Even though IMHO it should, it enforces nice programming)

I don't understand how not explicitly defining variables in a language that doesn't require it (or even imply that you should, unlike Visual Basic) is "nice programming."  PHP's variable declarations work completely well when defined implicitly and I don't see a purpose in forcing code to define them explicitly.  It's just stupid.

Having code croak on every notice would be stupid for the lack of a better word.

Offline Warrior

  • supreme mac daddy of trolls
  • Hero Member
  • *****
  • Posts: 7503
  • One for a Dime two for a Quarter!
    • View Profile
Re: ospap - Alpha1
« Reply #117 on: October 17, 2005, 05:38:05 am »
Forcing all variables to be declared not only helps when debugging code, wait sometimes it eliminates the need to debug since the reason is right there. I fail to see where there is no advantage to this.
One must ask oneself: "do I will trolling to become a universal law?" And then when one realizes "yes, I do will it to be such," one feels completely justified.
-- from Groundwork for the Metaphysics of Trolling

Offline iago

  • Leader
  • Administrator
  • Hero Member
  • *****
  • Posts: 17914
  • Fnord.
    • View Profile
    • SkullSecurity
Re: ospap - Alpha1
« Reply #118 on: October 17, 2005, 08:43:02 am »
You *should* declare all of a functions's variables at the top of the function, along with comments on what they do.  It helps you keep them straight, it forces you to stop and think about what you're doing, and it *greatly* helps anybody else who is looking at your code.  Doing it that way really is *nice* code.  Maybe it's not SO important in PHP, but right now I'm doing low level microcontroller programming, and it's very important. 

Offline Sidoh

  • x86
  • Hero Member
  • *****
  • Posts: 17634
  • MHNATY ~~~~~
    • View Profile
    • sidoh
Re: ospap - Alpha1
« Reply #119 on: October 17, 2005, 01:11:20 pm »
It's not important in PHP.  Debugging is a pretty negligible challenge in PHP, IMO.

Warrior, I'm not saying there's no advantage, I'm just saying its a moot effort.  It's trying to make PHP something it's not.  You're adding another unnecessary failure point.

Besides, if you use intuitive, predictable variable names, it doesn't do much for you declaring them at the beginning of a function.  Most PHP code I use is outside of a function anyway.  Most variables I handle are in a superglobal array, so moving them to a variable of lower scope is often a waste of time and resources.

Secondly, since variable types in PHP are determined completely by implicit methods, declaring variables doesn't increase the clarity of the code by that much.  Declaring a variable in PHP (obviously) would look like this:

Code: [Select]
$int_variable = 0;
$str_variable = '0';
$flt_variable = '1.0';
$bol_variable = true;

Declaring a variable's scope in PHP is obviously a different story.  I ALWAYS do this because not doing it is a complete waste of time, cleanliness of code and intelligence.  If you have something like:

Code: [Select]
$db = new mysql_db();

function get_username($user_id, $db) {
  // ...
}

get_username(1, $db);

It's pretty stupid when you can save a lot of trouble by doing:

Code: [Select]
$db = new mysql_db();

function get_username($user_id) {
   global $db;

   // ...
}

get_username(1);
« Last Edit: October 17, 2005, 01:22:05 pm by Sidoh »