ponderous2k
-
Posts
4 -
Joined
-
Last visited
Never
Posts posted by ponderous2k
-
-
Thanks for the reply.
OK. So each page request uses a fresh "copy" of the Validate::$valid and Validate::$errors static properties?
This topic stems from a question posed by another regarding instantiated VS static classes. The link and offending quote follows:
http://stackoverflow.com/questions/1185605/when-to-use-static-vs-instantiated-classes/1185633
Another thing about static data is that only one instance of it exists in your program : if you set MyClass::$myData to some value somewhere, it'll have this value, and only it, every where -- Speaking about the user, you would be able to have only one user -- which is not that great, is it ? -
I forgot to state why exactly what I think the problem is.
As you can see, the parameters are determined to be either valid or invalid, and are then added to the appropriate static array. After all inputs have been validated and none are determined to be erroneous, the static array $valid is used to pass information onto other classes and the database, like:
if (empty(Validate::$errors)) { CreateSubscription(Validate::$valid['email']); }
So can the data be corrupted by the time it gets to that point, say, if a third or fourth user were to submit data to the Validate class just before the other user's CreateSubscription method were called?
-
Hello, my first post here.
I created a Validation class that depends entirely on static methods. It appears to be working well, but perhaps I misunderstood exactly the purpose and the consequences of using static methods.
My class essentially looks like this:
class Validate { static public $errors = array(); static public $valid = array(); static public function Name($name) { if ($name != '') { self::$valid['name'] = $name; return true; } else { self::$errors['name'] = 'Name is empty'; return false; } } }
Does this create any chance whatsoever for a collision of data from multiple users? I am beginning to think it does, simply because from what I have recently learned about static methods, theyr'e essentially global variables because they are not instantiated. If that's the case, then it would seem possible that during times of heavy use, any application depending on this class would confuse submitted data.
Any thoughts?
Thanks in advance.
Data Collision when using Static Class Validation
in PHP Coding Help
Posted
Yes, this concept makes sense, and it's what I've based all my programming around thus far in my career. But for some reason I found myself doubting suddenly the reliability of my data.
Thanks for your help.