You can specify a version:
package { 'php' :
ensure => '5.2' ,
}
However, if that version of PHP RPM/Deb/package isn't available in your upstream repo, then you'll want to either:
Find an alternate repo that has that package, and add it to your repo list
Set up your own repo with the package
Install from your filesystem, by providing a path to the package:
package { 'php' :
ensure => '5.2' ,
source => '/some/path/to/php-5.2.rpm' ,
}