
sennetta
Members-
Posts
43 -
Joined
-
Last visited
Never
Everything posted by sennetta
-
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.
-
Have done. Cheers.
-
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.
-
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
-
5.2.3. Damn do I feel thick. Thanks very much for your time mate appreciate it. All the best.
-
Thanks. Yes the actual message itself might have been a good idea. Sorry about that :S Running your code gives me the following:
-
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?
-
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
-
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.
-
Help With Posting Arrays through Hidden Fields!?!?!
sennetta replied to Ryanz's topic in PHP Coding Help
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? -
Imposing Specifications Inside of Class Scope
sennetta replied to BrandonK's topic in PHP Coding Help
Sorry that should be <?php .... if (count($this->constant_2) >= $this->constant_2_max_length){ ... ?> up there. -
Imposing Specifications Inside of Class Scope
sennetta replied to BrandonK's topic in PHP Coding Help
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... -
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
-
Blimey they don't like edits here do they! Sorry wouldn't let me edit it. I meant:
-
Sorry wouldn't let me edit it.
-
Ok so I have the class name stored as a string, and the arguments stored in a separate array, and I have successfully created an instance of the class like so: private function createClass(){ require_once($this->className.".php"); $this->classInst = new $this->className; } How can I pass a varying number of arguments to the constructor of that class? I think I can do it by creating a method in the class to pass arguments, and then call a "begin" method which will set the class doing its stuff: private function createClass(){ require_once($this->className.".php"); $this->classInst = new $this->className; foreach ($this->args as $arg){ $this->classInst->addArg($arg); } $this->classInst->begin(); } but I'd rather not do that: passing them to the constructor would be a lot neater, and means I wouldn't have to subclass anything - I could just use an interface. What would you do? Many thanks once again.
-
Ah nice one. I shall look into that also. Cheers dude.
-
I meant:
-
Ah so I need to use variable variables? I've heard of these before but have had reason to explore them further. Many thanks for your reply - I shall look into it and reopen the topic if I get stuck. Cheers for the help.
-
This might not be strictly OOP related, but I wasn't sure and I didn't want to clutter the main board with something that might be inappropriate. I would like to create a function which takes a carefully formatted string as a parameter and creates an instance of an object with arguments taken from the string. The protocol is as follows: "ClassName_arg1_arg2" On being called the function splits the string (using http://uk3.php.net/split ?) and attempts to create an instance of the class ClassName with arguments Arg1 and Arg2, so, upon receiving such a string, the function essentially needs to carry out the following: <?php $obj = new ClassName("arg1","arg2"); ?> Note that more parameters may be added to the initial string, so it may be "ClassName_arg1_arg2_arg3_arg4_arg5" resulting in <?php $obj = new ClassName("arg1","arg2","arg3","arg4","arg5"); ?> or even simply "ClassName" resulting in <?php $obj = new ClassName(); ?> . I've had a think and a way I have come up with is getting the function to build the string "$obj = new ClassName(\"arg1\",\"arg2\");" and then get PHP to parse it, and essentially run the code it has just built. Is this even possible in PHP, and if so am I on the right track? Many thanks, Anthony
-
[SOLVED] Why won't this class blooming load?
sennetta replied to sennetta's topic in PHP Coding Help
Thanks for your pointers on require_once. Still no idea what was going on with the $classname argument apparently changing, but I had to go a different route anyways as the server I had to use only had php4 installed. Cheers Edit: marked as solved for tidiness -
I have a form handling script which sets the results of a form in a MySQL database. I am using a class to push data onto the database, and I have used this many times before without any problems. The problem I appear to be having is loading and instantiating the class. Classes are held in "lib/" directory and are called "ClassName.php". Script is in root directory and and creates objects using an autoload function: function __autoload($classname) { // generate file path $filePath = "lib/".$classname.".php"; if (file_exists($filePath)) { echo $filePath; require_once($filePath) or die("class not found"); } } Trying to load just one class called AddData: $dataIn = new AddData(); This outputs the following: lib/AddData.php Warning: require_once(1) [function.require-once]: failed to open stream: No such file or directory in D:\www\sarah\feedback.php on line 71 Fatal error: require_once() [function.require]: Failed opening required '1' (include_path='.;C:\php5\pear') in D:\www\sarah\feedback.php on line 71 According to the line "require_once(1)" the class is being renamed "1"... This has been bugging me for hours now, and I can't find what's wrong.... Can anyone help? Cheers, Anthony
-
Thank you very much for your help
-
Trying to query the following table: CREATE TABLE `gigs` ( `id` int(6) NOT NULL auto_increment, `postdate` int(30) NOT NULL default '0', `gigdate` bigint(20) NOT NULL, `location` text NOT NULL, `price` varchar(20) NOT NULL, `deleted` tinyint(1) NOT NULL default '0', PRIMARY KEY (`id`), KEY `postdate` (`postdate`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=8 ; with the following query: SELECT * FROM gigs WHERE deleted=0 AND id>-1 AND (id=(1 OR 1 OR 1 OR 6 OR 6 OR 6 OR 6 OR 6 OR 6 OR 2 OR 2)) ORDER BY gigdate and it's only returning the first result it finds when it should return three results: those with unique IDs 1,2, and 6. What's going on? Cheers, Anthony
-
[SOLVED] Where do you place class libraries?
sennetta replied to sennetta's topic in Application Design
Ah nice one. I'll stick it all above the web-accessible dir to avoid fannying around with permissions. Cheers.