I have PHP 5.5.9 and I activated php_intl.dll exyention and set its configuration in the active php.ini as the following:
[intl]
intl.default_locale = ar
; This directive allows you to produce PHP errors when some error
; happens within intl functions. The value is the level of the error produced.
; Default is 0, which does not produce any errors.
;intl.error_level = E_WARNING
When I try the following twig code:
{{ item.get_date('j F Y | g:i a')|localizeddate('medium', 'none', locale) }}
I got a fatal error:
Fatal error: Uncaught exception 'Twig_Error_Syntax' with message 'The filter "localizeddate" does not exist in "index.html" at line 53'
in
The official documentation there does not show how to install or add this filter to twig. I use simple PHP application without Symfony. The twig version 1.16.0
You're looking for the twig/extensions composer package, the github repo is at fabpot/Twig-extensions.
You mention you're using twig standalone, then you must have a Twig_Environment object. It has an addExtension method, you need to call it, passing a new instance of the Intl extension:
$env->addExtension(new Twig_Extensions_Extension_Intl());
Related
I am trying to decode and parse a base64 encoded YAML string with PHP. Everything works great until I call yaml_parse. Here is the entire programs (production will get the string from another source)...
$pdate = "LS0tIApwbGFzZWN0em9uZURheXM6IDMyNzY3CnBsYXNlY3R6b25lU3RhcnR0aW1lOiAwCnBsYXNlY3R6b25lU3RvcHRpbWU6IDE0NDAK";
$decoded = base64_decode($pdate);
yaml_parse($decoded, -1, $dCnt, $tzoneDetails);
print_r( $tzoneDetails );
When this runs the "PHP Fatal error: Uncaught Error: Call to undefined function yaml_parse()" is thrown.
I have installed YAML like this...
dnf install libyaml
Last metadata expiration check: 0:18:01 ago on Wed 19 Jan 2022 09:52:20 AM EST.
Package libyaml-0.1.7-5.el8.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!
I also added a yaml extension file in php.d but I am not sure it is required. I get the error both with and without the extension added. I have restarted apache with each change...
; Enable yaml extension module
extension=yaml.so
Any ideas?
I am trying to install libgit2 and php-git. I've successfully downloaded and built libgit2.However, I face problem when I try to install php-git.
This is how I try to install it :
phpize
./configure --enable-git2-debug
make
make install
There's no problem with phpize. However, when I use make and make install, following errors are showed:
./php_git2.h:180:3: error: unknown type name 'git_smart_subtransport'
git_smart_subtransport *smart_subtransport;
./helper.h:58:42: error: unknown type name 'git_checkout_opts'; did you mean 'git_checkout_options'?
void php_git2_git_checkout_opts_to_array(git_checkout_opts *opts, zval **out TSRMLS_DC);
/usr/local/include/git2/checkout.h:295:3: note: 'git_checkout_options' declared here
} git_checkout_options;
^~~~~~~~~~~~~~~~~
./helper.h:62:41: error: unknown type name 'git_checkout_opts'; did you mean 'git_checkout_options'?
int php_git2_array_to_git_checkout_opts(git_checkout_opts **out, zval *array TSRMLS_DC);
^~~~~~~~~~~~~~~~~
git_checkout_options
and there are more errors. Why this happens?
These errors indicate that the header files for libgit2 do not correspond to the version which the PHP bindings expect.
The bindings have their own libgit2 version which they link statically, so it does not need/want to use a system-installed version, but this is where the header files are being read from (as indicated by the paths in the output).
It looks to be a bug in php-git that it reads system header files for libgit2, but that's the root of the issue. The bindings do not want you to install libgit2 on your system. Unless you need a system libgit2 for another purpose, removing it should fix the issue.
You should file a bug with the php-git project as failing to work when a version of libgit2 is installed on the system is a build system bug in its code.
I should have been clearer. Looks like it's not finding libgit2.
I am deploying a symfony2 application to a server where php intl extension is not enabled. I have no say in this.
The answer to this question suggests a solution:
Possible to disable intl requirement for Symfony?
I have put the "symfony/intl": "3.0.*#dev" in my composer.json and everything updates fine. Must I do anything more to activate/enable it? In AppKernel like with bundles?
Now I get the following errors when I run check.php on deployment server:
PHP Fatal error: Uncaught exception 'ReflectionException' with message 'Extension intl does not exist' in /web/folk/eirik/030476/releases/20150528181203/app/SymfonyRequirements.php:658
Stack trace:
#0 /web/folk/eirik/030476/releases/20150528181203/app/SymfonyRequirements.php(658): ReflectionExtension->__construct('intl')
#1 /web/folk/eirik/030476/releases/20150528181203/app/check.php(6): SymfonyRequirements->__construct()
#2 {main}
thrown in /web/folk/eirik/030476/releases/20150528181203/app/SymfonyRequirements.php on line 658
I look at line 658 in SymfonyRequirements.php and find:
if (class_exists('Locale')) {
if (defined('INTL_ICU_VERSION')) {
$version = INTL_ICU_VERSION;
} else {
$reflector = new ReflectionExtension('intl');
ob_start();
$reflector->info();
$output = strip_tags(ob_get_clean());
preg_match('/^ICU version +(?:=> )?(.*)$/m', $output, $matches);
$version = $matches[1];
}
$this->addRecommendation(
version_compare($version, '4.0', '>='),
'intl ICU version should be at least 4+',
'Upgrade your <strong>intl</strong> extension with a newer ICU version (4+).'
);
}
I don't know much about this stuff, but I assume
new ReflectionExtension('intl') requires the intl exension to be enabled in php, which is no option for me.
But what is INTL_ICU_VERSION? And why is it not defined? And why won't the symfony/intl component fix this for me?
And btw
if (class_exists('Collator')) {
$this->addRecommendation(
null !== new Collator('FR_fr'),
'intl extension should be correctly configured',
'The intl extension does not behave properly. This problem is typical on PHP 5.3.X x64 WIN builds.'
);
}
I have also changed 'FR_fr' to 'en' here, this was an error given by check.php that disappeared when I made the change.
If you take a look into the file check.php you are running you'll see that it does not load the Composer autoloader therefore it makes no difference whether you have installed that Symfony Intl component or not, it'll keep failing because it's looking for a required extension that is not there. The SO question you linked does mention the problem got solved but it doesn't say that the check passed.
If that extension was your problem with your Symfony installation and the only locale you needed is "en" than the problem should have gone away already after you installed the Symfony Intl drop in replacement. Although if you want to run the check for other problems you can comment out those lines so the script can finish. Don't worry that script is totally decoupled from the framework, you can even delete it when you are done.
If you are using Capistrano for the deployment and you are running those checks on every deployment you might want to disable that as well, or customise that script for your needs.
i am trying to install FOSRest & FOSRestBundle
initially , i have specified following settings in the deps
[FOSRest]
git=git://github.com/FriendsOfSymfony/FOSRest.git
target=fos/FOS/Rest
[FOSRestBundle]
git=git://github.com/FriendsOfSymfony/FOSRestBundle.git
target=bundles/FOS/RestBundle
But that cause me into following error when i access http://localhost/Symfony/web/app_dev.php/
Fatal error: Declaration of
FOS\RestBundle\Routing\Loader\RestRouteLoader::setResolver() must be
compatible with that of
Symfony\Component\Config\Loader\LoaderInterface::setResolver() in
/home/logicase/public_html/Symfony/vendor/bundles/FOS/RestBundle/Routing/Loader/RestRouteLoader.php
on line 29
After that i tried following setting to make to the master branch and above error remains the same
[FOSRest]
git=git://github.com/FriendsOfSymfony/FOSRest.git
target=fos/FOS/Rest
version=origin/2.0
[FOSRestBundle]
git=git://github.com/FriendsOfSymfony/FOSRestBundle.git
target=bundles/FOS/RestBundle
version=origin/2.0
and now when i run php ./bin/vendors install
i get following message in console.
Installing/Updating FOSRest 5eb800bd63ba84e5fc7028386cb66373bc3efafc fatal: ambiguous argument 'origin/2.0': unknown revision or path not
in the working tree. Use '--' to separate paths from revisions
Installing/Updating FOSRestBundle c11ab9d990a1e0e979b1c8ab72cc9793b4b2dcb5 fatal: ambiguous argument
'origin/2.0': unknown revision or path not in the working tree.
I tried following settings for FOSRest which solved my problem for symfony 2
[FOSRest]
git=git://github.com/FriendsOfSymfony/FOSRest.git
target=fos/FOS/Rest
version=origin/0.6
[FOSRestBundle]
git=git://github.com/FriendsOfSymfony/FOSRestBundle.git
target=bundles/FOS/RestBundle
As you can see, there is no 2.0 branch : https://github.com/FriendsOfSymfony/FOSRestBundle/branches https://github.com/FriendsOfSymfony/FOSRest/branches The installation documentation does not talk about it. You should just remove the version lines.
I get this error on my production server (CentOS 5.4 and php 5.3.5) :
Warning: include_once(PharData.php): failed to open stream: No such
file or directory in /var/www/ZendFramework/library/Zend/Loader.php on
line 146
Warning: include_once(): Failed opening 'PharData.php' for inclusion
(include_path='/var/www/fw:/var/www/vmms:/var/www/ZendFw/library:.:/usr/share/pear:/usr/share/php')
in /var/www/ZendFw/library/Zend/Loader.php on line 146
Fatal error: Class 'PharData' not found in
/var/www/vm/app/Backup.php on line 40
And this is the code which fail :
$phar = new PharData($imageBackupFile);
$phar->buildFromDirectory($imageDir);
Logger::info("Image directory backed up to: $imageBackupFile");
This code is working fine on my own computer.
PharData should be included by default in php 5.3+ ...
Thanks for your help!
UPDATE :
I am using the Zend Auto loader feature to load the good php files using this code :
require_once("Zend/Loader/Autoloader.php");
$autoloader = Zend_Loader_Autoloader::getInstance()->setFallbackAutoloader(true);
Zend autoloader is doing the include_once(PharData.php).
Just because Phar is bundled by default in PHP 5.3 doesn't mean that it's necessarily included in your install. When you build PHP with ./configure, you can pass the --disable-phar to disable the Phar extension.
To confirm this, run the following script:
<?php
phpinfo();
?>
One of the first sections to appear will be the Configure Command section. Review this section to see if the --disable-phar switch is present, and if there is a Phar section to the page in general.
If it's not present, you'll need to contact your host to have it enabled. There's a decent chance, however, that they won't do it for you since it could impact other users depending on how their servers are set up. If this is on your own machine, you'll need to either rebuild PHP without that switch, or install Phar manually from PECL (no idea if this would still work in 5.3, but I don't see why it wouldn't).