Jump to content


  • Content Count

  • Joined

  • Last visited

Community Reputation

3 Neutral

About deathbeam

  • Rank
  • Birthday 04/08/1996

Contact Methods

  • Website URL

Profile Information

  • Gender
  • Location
  • Age
  1. So, I am not very experienced with regexes, so I wanna ask if this code can be simplified with preg_match? It is code from my framework on what I am working for adding routes. To explain what is "default" and "MAP", here is example usage. And, callable is called via call_user_func_array if that helps. // mapping routes $fw->route('home: GET|POST /', 'home'); // provide ReST interface by mapping HTTP requests to class method $fw->route('MAP /rest', 'some_class'); // default route (404 page) $fw->route('default', 'error'); And this is route method. public function route($pattern, $callable) { $pattern = strtr($pattern,array(' '=>'')); if ($pattern == 'default') { $this->default_route = $callable; return $this; } $arr = explode('/', $pattern, 2); $method = $arr[0]; $route = '/'.$arr[1]; if (strpos($arr[0], ':') !== false) { $arr = explode(':', $arr[0], 2); $name = $arr[0]; $method = $arr[1]; } if ($method == 'MAP') { foreach ((explode('|', self::Methods)) as $method) { $this->route((isset($name)?$name.':':null).$method.$route, $callable.'->'.strtolower($method)); } return $this; } $this->routes[] = array($method, $route, $callable, isset($name)?$name:null); return $this; }
  2. I was not asking about using autoloader, that will defeat purpose of simplifying my code, why should I use autoloader when my framework is only single php file? Oh, thank you very much for this info. I am focusing on ability to use my fw on shared hosting, so then I will scrap this idea.
  3. Gosh, that design is messy. Try http://getbootstrap.com/getting-started
  4. There is also another scenario. Like this: class base{ public function setParam($key, $callable){ $this->params[$key] = $callable; } internal function run(){ foreach($this->params as $key=>$callable) $callable(); } } $base = new Base(); // if internal was possible, users will not be able to call this method outside this file. Especially usefull for frameworks and PHP applications. $base->run(); If you know what I mean. And yes, PHP isn´t C#, but PHP hosting is cheaper than ASP.NET. So it is pity that internal does not exists in PHP.
  5. Yes, it have protected, private and public. But it misses internal. Internal functions and vars are visible only in file.
  6. So I am working on my own PHP framework and I am using this: php_value auto_prepend_file library/fw.php php_value auto_append_file library/fw.php To auto prepend and append file. In that file I have check if instance of core class located in fw.php is defined so it will not prepend and append duplicates. With this I reduced index.php code by these 2 lines // This should be at beggining of index php $fw = Base::getInstance(); // This should be at very end of index.php $fw->run(); Is it good or bad way?
  7. Only thing I really miss from PHP is "internal" access modifier. Before I was making libraries and extensions in C# (like game frameworks, Tiled implementations, GUI loaders). Now, when I am working on my own PHP framework, I really miss internal, I was using it a lot in C#. Is internal planned to be added in PHP 7 or is it already in PHP 5.6 or it will never be added?
  8. If you are using windows, then simply download https://windows.github.com/ GitHub for windows so you do not have to learn git at all
  9. If you are echoing PHP values to html and you need to rewrite all relative links then yes, this is probably best method. Otherwise use simple string merging and echo values with var like $newURL. before them
  10. I am always using PDO bind when using prepary (actually, If you will not use bind and pass value directly to prepary it will throw exception).
  11. It will change to what url will point relative urls in your document. F.E when your domain is www.example.com, this relative path <a href="test">Test relative link</a> will point to www.example.com/test. But if you will change base to f.e this one <base href="http://www.new_example.com/"> "Test relative link" will point to www.new_example.com/test
  12. Welcome here. I personally do not like w3schools, but it have some valuable tutorials for beginners. Good luck with learning PHP
  13. I am using chrome too, and when I scroll to About Me, About Me is highlighted and same is with Resume. On my PC your site is working perfectly.
  14. Yep, short tags aren´t enabled on some hosts so I was not sure if they are allowed on this site
  • 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.