Jump to content

sennetta

Members
  • Posts

    43
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

sennetta's Achievements

Member

Member (2/5)

0

Reputation

  1. This thread is four years old, but it comes up on Google. Here is something that might be related for future people who come across this: http://bugs.php.net/29032 Basically $_SESSION is destroyed/unwritable/unpredictable/crap when called in destructors (which could be after execution has finished). Also, the bug report is 7 years old, so may not be the case at all. All I can say is that for me, calling $object->__destruct(), where $object is a singleton, works fine, but is not a very neat way of doing it.
  2. Thanks for your reply. Here is the output. Fatal error: Uncaught exception 'Zend_Config_Exception' with message 'Comments starting with '#' are deprecated in /Users/username/www/application/config/mac-desktop_config.ini on line 3 Comments starting with '#' are deprecated in /Users/username/www/application/config/mac-desktop_config.ini on line 4 Comments starting with '#' are deprecated in /Users/username/www/application/config/mac-desktop_config.ini on line 38' in /Users/username/www/application/library/Zend/Config/Ini.php:117 Stack trace: #0 /Users/username/www/application/bootstrap/mac-desktop.php(220): Zend_Config_Ini->__construct('/Users/username...', 'main') #1 /Users/username/www/application/web_root/index.php(7): include('/Users/username...') #2 {main} thrown in /Users/username/www/application/library/Zend/Config/Ini.php on line 117 This is the code from the class Zend_Config_Ini.php: set_error_handler(array($this, '_loadFileErrorHandler')); $iniArray = parse_ini_file($filename, true); // Warnings and errors are suppressed restore_error_handler(); // Check if there was a error while loading file if ($this->_loadFileErrorStr !== null) { /** * @see Zend_Config_Exception */ require_once 'Zend/Config/Exception.php'; throw new Zend_Config_Exception($this->_loadFileErrorStr); } And this is the config file that it's having trouble with. [main] database.adapter = PDO_MYSQL #database.cfg.host = 89.234.32.172 #database.cfg.host = 10.10.10.170 database.cfg.host = localhost .. snip .. [images] # possible placeholder 6564a3dcd68ff39a732b6869eeb6a35a.jpg product.placeholder.src = /images/ product.placeholder.path = /web_root/images/ product.placeholder.height = 200 product.placeholder.width = 200 I could just change the comments, but there are LOADS more of them.
  3. I inherited an application, and my install can't handle # comments (running 5.3.0 on a mac). It keeps on throwing Zend config exceptions. Is there anything I can set in php.ini to allow this? Cheers
  4. 5.2.3. Damn do I feel thick. Thanks very much for your time mate appreciate it. All the best.
  5. Thanks. Yes the actual message itself might have been a good idea. Sorry about that :S Running your code gives me the following:
  6. Thanks for responding. Yes cheers for that I didn't see it. So the code now looks like this: protected function defineFields() { return array( "testInputElement" => array( "type" => "InputElement", "errorMessage" => "Please input a whole number between 30 and 90", "elementOptions" => array(), "validation" => function() {return false;} ), "testInputElement2" => array( "type" => "InputElement", "errorMessage" => "Error Message for form field 2 goes here", "elementOptions" => array(), "validation" => function() {return false;} ) ); } And it's still giving a parse error. Is there anything else I've missed?
  7. Hey there. I'm new here. I'm building an abstract form generation/validation class, which is to be subclassed for each different form, and it's time to develop the data validation routines. What I'd like to do is similar to Yii's way of defining the data model through a function of a Model class, which returns an array of validation flags, but instead of passing a load of different flags, I'd like to pass the validation function itself. PHP can do anonymous functions, and pass them as a variable, but so far I have not have any success passing an anonymous function in an array (which after all is just a collection of variables). This gives a clearer picture, and also shows what I am trying at the moment. It is part of the child class of the abstract Form class: protected function defineFields() { return array( "testInputElement" => array( "type" => "InputElement", "elementOptions" => array( "errorMessage" => "Please input a whole number between 30 and 90", ), "validation" => function() { return false; } ), "testInputElement2" => array( "type" => "InputElement", "errorMessage" => "Error Message for form field 2 goes here", "elementOptions" => array(), "validation" => function() { return false; } ), ) ); } Note the attempt to define the array key 'validation' as an anonymous function. This throws a syntax error. After the parent abstract Form class receives this array of values (by calling defineFields() in the child class), I would like to assign the passed function as the validate function of the FormElement class, so that it can validate itself. I have tried defining the function elsewhere in script (both inside and outside the class), and passing it through the array as variable, but this also yields a parse error. I have also looked at create_function(), but I can't see how I would assign it as a class function to the FormElement class. Has anyone have any experience I could call upon? Obviously I could pass in a load of "int", "max" => 200, "min" => 100", but this would take a lot more work - it's easier and more extensible just to define one function per form field. I've kept the above as concise as possible for briefness, but please tell me if there is not enough info or it makes no sense, and I'll elaborate. Many thanks, sennetta
  8. Thanks very much. That was exactly what I needed. Here is the code I wrote. <?php private function createClass(){ require_once($this->className.".php"); // create class instance using factory method in class $this->classInst = call_user_func_array( array( $this->className, 'factory'), $this->argsArr); // $argsArr is array of arguments created // when the input string is exploded } ?> and it works, by crikey.
  9. Not 100% sure what the question is, but I wouldn't serialise anything. If it's just an array you're transferring through POST perhaps use implode() to turn the array into a string, stuff it in the hidden html field, and then explode() to turn it back again in the handling script. Does this help?
  10. Sorry that should be <?php .... if (count($this->constant_2) >= $this->constant_2_max_length){ ... ?> up there.
  11. Might sound daft and cumbersome, but could you create another class (static maybe) that holds all the constants, and then give that class get methods, and use those? <?php class Constants { private $constant_1 = 3; private $constant_2 = "my_string"; private $constant_1_max = 10; private $constant_2_max_length = 100; private $defaultConstant_1 = 10; private $defaultConstant_2 = false; public function getConstant_1() { if ($this->constant_1 > $this->constant_1_max) { return $this->constant_1; } else { return $this->defaultConstant_1; } } public function getConstant_2 { if (count($this->constant_2) <= $this->constant_2_max_length){ return $this->constant_2; } else { return $this->default_constant_2; } } } ?> Other than that I don't know - I doubt you one can have fields available to one method and not another within a class. BWT I haven't tested this at all, so it probably won't even compile...
  12. Add more comments - I always have a big block comment at the top saying exactly what the class does so that people don't have to decipher code. Also neaten the code a bit to make it more readable
  13. Blimey they don't like edits here do they! Sorry wouldn't let me edit it. I meant:
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.