I have been using the cool reflection class in my framework. I wonder whether or not ReflectionClass is future-compatible? For example, in PHP5.3 or PHP6.
Classes that are bundled with PHP don't tend to just "disappear" ; especially classes that have been added only "lately" -- the Reflection API has only been added in PHP 5.
For PHP 5.3, it is still here (classes like that don't go away in a minor version) ; and, in fact, it is being improved with PHP 5.3.2 -- there is a new method, from what I've heard.
For PHP 6... Well, always in motion the futur is, as one would say... But I'd bet the reflection API will stay : it is really useful, is a great addition to the language, and is used by several modern tools.
Yes, go4it!
Reflection is quite new and used in many big frameworks like Zend Framework or Doctrine ORM.
Related
I'm building an MVC framework and I was thinking that most of the classes used in the making of an application are models. So since I know that every model is inside a folder I could just use the native __autoload() function to implement a "feature" (that obliviously you can enable and disable as well) that automatically loads a model (Lazy programming).
Is it good or should I discard this idea? If the latter: why?
If you're building a PHP framework, it might be worth looking into the PSR-0 standard for autoloading. I'm afraid I don't know much about it, but I believe a number of substantial frameworks and libraries have agreed to abide by it for interoperability. I believe that would include Symfony2, Propel2 and the next major version of Zend Framework.
There is absolutely nothing wrong with relying on the __autoload() function, as long as you have a consistent naming scheme.
In fact, it's often better to use autoloading - it stops you from including classes "just in case" you use them.
Addendum
Doctrine 2 Annotations
Can you give me any reason one is better than the other ?
Here my list for now :
Addendum is a project dedicated for that
Addendum seems to have more functionnalities
Addendum API seems easier to use
Doctrine has more support and more people involved
Doctrine seems to be a project more alive
Doctrine is fully compatible PHP 5.3, whereas Addendum seems to be trying to become compatible (see home page)
Doctrine Annotations can be cached easily
The decision is not easy...
I suppose I'd rather use the Doctrine's component :
I've never heard of Addendum -- while I've heard a lot about Doctrine (and have used it several times)
Which means more community and support for Doctrine
Doctrine is used by some big Frameworks (symfony ; and can easily be integrated with Zend Framework)
Which means chances are higher that you'll already use Doctrine ; and find developers who are familiar with its syntax
Maybe less important for you, But some guy from Doctrine's team has done some work on getting Annotations integrated into PHP
There is a RFC : Request for Comments: Class Metadata
For now, it doesn't seem this is going to be integrated into PHP, but it means there is works done by the Doctrine's team, that shows their solution has some thinking
For what it's worth...
I've been using Addendum for a year now, and I've found it ridiculously easy to use. Its extension to the PHP Reflection API is seamless, and it supports far more use cases than Doctrine Annotations component.
It lacks namespaces support, but I could patch AnnotationMatcher class so it accepted namespaced classes (without getting false matches from docblock tags) and it has worked like a charm.
Doctrine's annotations takes into account PHP 5.3 use statements. That's the only thing that Addendum does not do and IMO it wouldn't be so trivial to implement.
I am looking for a "lite" php framework like codeigniter that doesn't generate anything or make me follow conventions, etc. I have a lot of legacy databases to connect to and I don't know whether or not CI will be able to connect to them all so I thought I'd see if anything else is out there.
Again, not after anything that worries me to death about singular and plural names, makes me have a database in a certain fashion, or anything that gets in my way. No offense by that. I have other projects where that is just fine and I use RoR for that. I just don't want that here because if a framework is built around that like RoR is they tend to be difficult to use with existing legacy databases.
Thank you.
CakePHP is the most popular.
There's a fork of CodeIgniter called Kohana.
The connectivity to the legacy database shouldn't be an issue of the framework though, I guess it's more a PHP issue if the connection won't work.
http://alternativeto.net/software/codeigniter/ Will give you a few alternatives.
Check out Laravel. http://laravel.com/
It is really clean and well documented and has some really useful features which I didn't find in CodeIgniter or CakePHP which I previously worked on. I tried it out for one of my recent projects and I was really impressed !
The Zend Framework might be your best bet:
Zend Framework is an open source,
object oriented web application
framework for PHP 5. Zend Framework is
often called a 'component library',
because it has many loosely coupled
components that you can use more or
less independently.
Since you can use the components independently, you will have more flexibility in choosing your models and data access. Be warned though, there is a steep learning curve.
apparently Qcodo is supposed to be a lot like rails according to http://gadgetopia.com/post/4726
other than that (and symfony, Yii, and CakePHP) if you're comfortable with CI, do go for Kohana, as Cassey mentioned
You could also just use PEAR or some wrappers. if you have legacy databases I wonder if you might have older php/mysql tht it sits on, in which case a lot of the newer frameworks that are updated for the latest/greatest might not work for you anyway.
I'd look at Kohana or Yii. Sure, Yii has scaffolding, but you don't HAVE to use that if you don't want to. Just as with Ruby on Rails.
Both are MVC frameworks that are very object oriented. How you connect to databases is totally up to you.
You can use the ORM in Kohana without following their naming conventions, you just have to let the Models know the name of your tables and primary keys (otherwise you have to follow the convention, of course).
Check out Symfony
The last version is very lite and all extra packages are optional and the core is so lite and also it is so clean and well documented .
i want to convert zend php to cake php but not finding correct book and guiding to do that????
Just download Cake, install and configure it and then gradually migrate your existing code into it. There is no standard recipe how to do that. You have to do that manually, class by class, line by line. Cake's API is quite different from ZF's API so this will take a while, depending on how much coupling you got. Also, ZF does not have any ActiveRecord, while Cake is built around that, so the database part will probably take longest.
Migrating from framework to framework is a sure thing to introduce bugs into the code. If you don't have a solid unit-test base already, it's a good opportunity to add a test before migrating a class.
On a sidenote: why do you want to to do that anyway? Cake is compatible with PHP4 and has a rather messy and slow performing codebase. Migrating your application from ZF to Cake is likely a downgrade. And as others pointed out, you could have Cake and ZF coexist.
I suggest you learn how to use both frameworks and then port the code manually. There are no tools that will do this for you; there simply is no way to do this automatically, especially given then highly flexible nature of ZF.
Learn both, use your understanding to migrate the code.
i am looking for a new php(5) framework it must be lightweight(x<500kb), oop, have orm, active record built in, simple to learn, fast to use, active community and dev.
I need it for small, personal app development.
My php skills are quite low and i have .net background. I have previously used LightVc+cough and codeIgnitor php frameworks.
There are so-many frameworks there and it is quite hard to find the best.
I have checked the other threads here but they are to old to consider sustainable.
Thanks for your time.
I think you dig out the http://www.phpframeworks.com/. It has details about each and every accepted framework.
Code Igniter is very popular and also supports PHP4: http://codeigniter.com/
Unlike .NET and miscellaneous other programming languages, you really don't need a framework to write a PHP application. In fact, I'd advise against it. Learn the language, not a framework.
For someone with low PHP skills I'd say codeigniter although it doesn't have ORM built-in (it has a sort of lightweight active record class), but there are tutorials on how to use Doctrine (a good PHP ORM solution) with it.
However if you want a PHP5 only framework (as in written to take full advantage of PHP5) then I'd suggest looking at Kohana (a PHP5 only fork of codeigniter), Yii or Zend framework.