Jump to content

phant0m

Members
  • Posts

    164
  • Joined

  • Last visited

    Never

Everything posted by phant0m

  1. Hehe, yeah that may be a problem of mine.. spending too much time thinking instead of just giving things a shot Thanks of lot for the input.
  2. Hey In my spare time, I am working on my PHP framework. Now, to help with development and quickly discover where I miss a type cast, I have adopted to check all parameters that are passed to a method using a function. For instance: public function __construct(&$target = null, $depth = 1){ $this->validateArguments( array(1 => 'int'), array(1 => $depth) ); And the code that triggers the exception: public function testPhpFreakType(){ $obj = 1; $p = new Xcms_DataStructures_Pointer($obj, "1"); } 0: |--------------------------------------------------| 1: |--Exception: 4cfe2e86ca5970.22624423 - Full Trace | 2: | Tue, 07 Dec 2010 13:54:30 +0100 3: |-Class: 4: | Xcms_Exceptions_InvalidArgument 5: |-Message: 6: | Argument #1 of Xcms_DataStructures_Pointer:__construct() is no _null:int 7: | Stack offset: 3 8: | 9: |-Trace 10: | #0 D:\www\xcms_rev\core\exceptions\invalid.argument.helper.class.php(133): Xcms_Exceptions_InvalidArgumentHelper::factory(1, '_null:int', NULL, 2) 11: | #1 D:\www\xcms_rev\core\basic.class.php(80): Xcms_Exceptions_InvalidArgumentHelper::validateArguments(Array, Array, Array, 1) 12: | #2 D:\www\xcms_rev\core\data.structures\pointer.class.php(49): Xcms_Basic->validateArguments(Array, Array) 13: | #3 D:\www\xcms_rev\core\data.structures\pointer.test.php(73): Xcms_DataStructures_Pointer->__construct(1, '1') 14: | #4 [internal function]: Xcms_DataStructures_PointerTest->testPhpFreakType() 15: | #5 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(737): ReflectionMethod->invokeArgs(Object(Xcms_DataStructures_PointerTest), Array) 16: | #6 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(627): PHPUnit_Framework_TestCase->runTest() 17: | #7 C:\xampp\php\PEAR\PHPUnit\Framework\TestResult.php(629): PHPUnit_Framework_TestCase->runBare() 18: | #8 C:\xampp\php\PEAR\PHPUnit\Framework\TestCase.php(575): PHPUnit_Framework_TestResult->run(Object(Xcms_DataStructures_PointerTest)) 19: | #9 C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php(766): PHPUnit_Framework_TestCase->run(Object(PHPUnit_Framework_TestResult)) 20: | #10 C:\xampp\php\PEAR\PHPUnit\Framework\TestSuite.php(742): PHPUnit_Framework_TestSuite->runTest(Object(Xcms_DataStructures_PointerTest), Object(PHPUnit_Framework_TestResult)) 21: | #11 D:\www\xcms_rev\core\testing\manager.class.php(83): PHPUnit_Framework_TestSuite->run() 22: | #12 D:\www\xcms_rev\core\testing\manager.class.php(56): Xcms_Testing_Manager->testClass(Object(ReflectionClass)) 23: | #13 D:\www\xcms_rev\cache\pkg\scripting\script_1.php(3): Xcms_Testing_Manager->run(Object(Xcms_Url_DefaultRequest)) 24: | #14 D:\www\xcms_rev\core\util.lib.php(340): include('D:\www\xcms_rev...') 25: | #15 D:\www\xcms_rev\core\packages\scripting\controllers\scripting.controller.php(66): Xcms_Util::sandboxedInclude('cache/pkg/scrip...', Array) 26: | #16 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(210): Xcms_Packages_Scripting_Controllers_ScriptingController->execute(Object(Xcms_Packages_Scripting_Models_ScriptModel), Object(Xcms_Templating_Context)) 27: | #17 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(170): Xcms_Mvc_Controllers_DefaultController->runScript(1, 0, Object(Xcms_Templating_Context)) 28: | #18 D:\www\xcms_rev\core\mvc\controllers\default.controller.php(132): Xcms_Mvc_Controllers_DefaultController->runScripts(0, 0, Array, Array, 1, 0) 29: | #19 D:\www\xcms_rev\index.php(15): Xcms_Mvc_Controllers_DefaultController->run() 30: | #20 {main} 31: |--------------------------------------------------| I think this speeds up my development quite a bit, because I can catch errors very early in the development process. I can give multipe possibilities of what is allowed for each parameter, not just a single possibility. Also, it is possible to register custom type/validity-checks on both global and local scope. One thing I do worry about, however, is the the performance. Of course, I could just make the funciton do nothing in production code, if it takes too much time, or I could write a script to remove all calls to that function. When I started learning python a while back, the concept to just code to interfaces instead of types seemed very intuitive and made my code much more flexible. Of course that is what I do with PHP as well, but I it's not entirely the same. So now, coming back at my PHP code and having introduced features of static languages such as type checking, I worry about whether that is the right approach. What are your thoughts on the matter?
  3. Ah yes, LogicException it is, not Error Any other thougts on this?
  4. I have been thinking about using "LogicError", because in a way, it is I think, since you are not supposed to assign to it. The other I was thinking about was something along the lines of Myframework_Types_Property_ReadOnlyException but I don't like that level of verbosity too much, to be honest
  5. Hi I am implementing a read-only access to some specific attributes of a class via the magic __get method. I intend to raise an exception when trying to write to it using __set, but I'm not sure which exception is suitable to use. Is there any predefined exception to indicate such an error or should I just go ahead and define my own?
  6. No, I want a simple way to check whether I can do foreach on something. That something could be an array, but also an object that implements the Traverseble interface, i.e. has an Iterator of some kind.
  7. How can I check, whether something can be iterated with for, without doing it the hard way with exceptions? Would I just do "is_array or instanceof Traversable"?
  8. do you get any errors? Have you tried error_reporting(E_ALL); and display_errors?
  9. Hi I have a parent/child structure and I'd like to be able to insert them all at once. INSERT INTO table (parent_id, description) VALUES (null, parent item), (<expression to refer to the auto_increment value of the previously inserted row>, child item) LAST_INSERT_ID() always return the AUTO_INCREMENT from the last query, so I can't use that. Is there any way to accomplish doing it in one query instead of inserting the parent item in a query, and all the children in a second query?
  10. Couldn't you edit the template and remove the class thingy altogether?
  11. I was wondering what Class naming guidelines you follow for autoloading and how you put them into directories Some_NameSpace_Class_TypeOne --> Some/NameSpace/Class/TypeOne.php or some/name.space/class/type.one.class.php I'm just trying to collect some ideas to see what ideas people have come up with.
  12. Like this? $method = 'isTesting'; $test->$method(); or do you have something else in mind? Yes, something like this: $this->type = 'SomeClass'; $some_class = new $this->type('Constructor Param'); I know that this works^^ - but was if there was a method with the same name? public function type($param){} @ignace, I guess you're right. But do you know where I can read up on this?
  13. As the topic title suggests, how does PHP deal with object properties that has the same name as a method? class Test{ protected $isTesting = true; public function isTesting(){ var_dump($this->isTesting); } } $test = new Test; $test->isTesting(); But what if I wanted to run a function with the name that is stored in the property? The code above behaves as intended, it outputs "true". Can this naming be used without concern? Or are there any pitfalls?
  14. http://www.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
  15. So... here's a little summary and new insights into the problem. Scenario: Bad Syntax in one of my PHP files. What happens? Apache crashes, no output. Apache's log: Parent: child process exited with status 3221225477 -- Restarting. I have a custom error handler and I have a custom exception handler. function my_exception_handler($exception){ chdir(XCMS_Config::SCRIPT_PATH); $file = fopen('log.log', "a+"); fwrite($file, $exception->getMessage()); fclose($file); echo Exceptions_Wrapper::getFullLogMessage($exception); } When I comment the "echo" line, everything works as expected: I get the default PHP Parse error message. However, when this line is there, the phenomenon described above happens. If I exchange the line in question with a simple echo "test"; I get the usual PHP parse error and the string "test" on a new line AFTER the parse error. Next thought: There is something fishy with the code inside the static method that is called. :arrow: I have commented all the code inside that method: No effect. Apache still crashing. I reckon that this means, that the method is not even invoked. I use autoloading to load all my classes. Whatever other error or exception occurs, the Exception_Wrapper is always loaded without any problems. Only in this case it fails. Then I have added this code to dump the errorMessage into a log file. Result: Consequently, I have used ini_set to et bug_compat_42 to off. Result: Everything works fine now. It turns out I have skipped some session handling for testing purposes. When I reactivate that part, it always works no matter what bug_compat_42 is set to. What happens in that part: I have a User object that pulls some information of $_SESSION['user'] into ->user, or creates it if it's not in the session. It is a simple array with the settings of the user. At the end, in __destruct, I write that information back into the session, so that I still have my settings the next time. In the global context, I have a variable called $user that holds an instance of the User class. A while ago, I was struggling with PHP crashes because register_globals was messed up, and as a result it would store the entire $user in $_SESSION['user'] resultint in unpredictable behaviour. I have a function that reverses the effects register_globals if it's switched on, and never had a problem since then. Anyway, register_globals is disabled on my test environment, so it has no effects. The problem described above only occured WITH register_globals. Also, let's not forget that this new problem only occurs, when I don't do any session handling. (I know that session_register causes this message usually, but it is not to be found in my code) And the notice in the quote above, ONLY appears on a syntax error. I just can't see the connection between all of this :S
  16. Hmm... now it crashes on all syntax errors. I have a custom error handler. When I disable that, Apache doesn't crash anymore. However, the error_handler is not responsible for parse errors, right? So it shouldn't have an effect.
  17. [sun Jun 13 14:13:16 2010] [notice] Parent: child process exited with status 3221225477 -- Restarting.
  18. I am trying to integrate PHPUnit into my framework. That's why Apache is involved. Everything works fine as long as all the files that are parsed while PHPUnit is running are without syntax errors. Apache is crashing because I get a nice dialogue telling me "Apache HTTP Server has stopped working" If the very same file with the same syntax error is included at an other time, I get the usual Syntax error message.
  19. Hi My Apache crashes when I have a PHP file with bad syntax during a PHPUnit test. Does anyone know how I can stop Apache from crashing and have the test fail instead?
  20. Here's how I got around the problem: public function __wakeup(){ $reflection = new ReflectionClass(__CLASS__); $properties = $reflection->getProperties(); foreach($properties as $property){ $this->{$property->getName()} =& self::$instance->{$property->getName()}; } } public function __sleep(){ return array(); }
  21. I just made an error when typing the code above^^ Just assume that I wrote $this->theme->var['test'] = 'XYZ'; Anyway, I have discovered what messes with my variables: PHPUnit. I was trying to integrate this into my Framework to automate unit testing. But somehow it breaks the relationship between the original $theme and the $theme after PHPUnit has run. However, once PHPUnit has run, $theme is still an instance of the Class it was before, but $theme === $theme->getInstance() yields false. How can PHPUnit change that, if it is unable to create a new instance of ThemeEngine directly, because the access is set to private? //Edit: I have just had a look at PHPUnit's code. Apparently it serializes all my objects in the global scope and unserializes them when it's done. That would explain how the relationship is broken. I guess I'll just have to implement __sleep and __wakeup accordingly. Any other ideas?
×
×
  • 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.