I have a similar problem as here
I am using Apache2 server.
I have made a simple extension named extensionV2.so
I can load the extension and use it in my code when i do
extension = extensionV2.so in php.ini.
and use its functions in my php file.
But if i use
<?php
dl('extensionV2.so');
var_dump(get_loaded_modules());
?>
I get the error
Fatal error: Call to undefined function dl() in /var/www/html/My.php on line 9
Note:
I am using php 5.3
According to phpinfo()
Thread Safety - disabled
Safe Mode - Off
enable_dl() = On
I get the desired output via php -r in the terminal. I am aware of dl() not in use anymore via apache2handlers... is there any alternate option to workaround the dl() issue?
You don't need to dl() for loading your extension, if your extension is compatible with your PHP (PHP-extension should match the PHP server in thread safety, API number and compiler version) then, after restarting your server you should see your extension name (in your case extensionV2) in your phpinfo() page, otherwise there is a problem in loading your extension.
EDIT-1
Here is an alternate for using dl() in your code:
// Try to load our extension if it's not already loaded.
if (!extension_loaded('extensionV2')) {
if (strtolower(substr(PHP_OS, 0, 3)) === 'win') {
if (!dl('extensionV2.dll')) return;
} else {
// PHP_SHLIB_SUFFIX gives 'dylib' on MacOS X but modules are 'so'.
if (PHP_SHLIB_SUFFIX === 'dylib') {
if (!dl('extensionV2.so')) return;
} else {
if (!dl('extensionV2.'.PHP_SHLIB_SUFFIX)) return;
}
}
}
Related
In an unrelated, vanilla PHP project, I simply have this:
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'vendor/autoload.php';
It pulls in just fine. Following CakePHP 2.10's standards, I put all associated (composer'd) files in the app/Vendor folder and try this in my controller:
public function index($load = null) {
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
include(APP . 'Vendor' . DS.'autoload.php');
I get:
syntax error, unexpected 'use' (T_USE)
Any attempts to move the use around end up not working, so I ignore them and try to get it to work without namespaces.
require_once(APP . 'Vendor' . DS.'autoload.php');
require_once(APP . 'Vendor' . DS.'phpmailer\phpmailer\src\PHPMailer.php');
I know it's loading the PHP file via require_once, and that file includes the PHPMailer class. I get this error:
Error: Class 'PHPMailer' not found
But I know that class has to be present somewhere, because I loaded it. Code looks like this, to call it:
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.zoho.com'; // Specify main and backup SMTP servers
etc. So I'm not sure if this version of PHPMailer refuses to work without namespaces, which CakePHP 2 doesn't support? All other questions on Google do not seem to help me.
You're putting the use statements in the wrong place; they need to go at the top of your file (after any namespace declaration) as they are not block-scoped. Read the PHP docs.
You can mix namespaced and non-namespaced code, you just need to be aware that it's going on.
I'm developing a plugin that has an action which decide the view to render according to data properties:
example:
class ProfilesController extends MyPluginAppController {
public function myaction($id){
//..omitting checks..
$profile = $this->Profile->read(null,$id);
//Stuff
if($this->hasDedicatedViewFor($profile)){
$this->render('profiles'.DS.$this->getDedicatedViewFor($profile));
}
//Else render default action view
}
}
While this controller was inside the APP everything was working right,
after moving into Plugin, cake says:
Error: Confirm you have created the file:
.../app/View/Plugin/MyPlugin/Profiles/myaction_secondary.ctp
While I'd expect to load it from:
.../plugins/MyPlugin/View/Profiles/myaction_secondary.ctp
While I'd expect to load it from:
.../plugins/MyPlugin/View/Profiles/myaction_secondary.ctp
It is attempting to load the default plugin path
If you trace through the code for finding template files it is checking multiple paths for plugin view files:
$paths = $this->_paths($plugin);
$exts = $this->_getExtensions();
foreach ($exts as $ext) {
foreach ($paths as $path) {
if (file_exists($path . $name . $ext)) {
return $path . $name . $ext;
}
}
}
The path in the error message is the last place CakePHP looks for a plugin view path, but it should also be checking the plugins directory. Debug the above code to see where CakePHP is looking for files if in doubt.
The path being wrong in the error message probably indicates using an out of date version of CakePHP; it's always, always a good idea to maintain your applications running the most recent maintenance release for the major version you are using. From the info provided that's 2.7.3 at the time of this answer.
I'm on a shared host and ini_set function is disabled for security reasons. I'm trying to deploy CakePHP 2.4.1 on this host. Fresh cake installation results in a blank page, with no errors shown, instead if I comment these lines:
\lib\Cake\Model\Datasource\CakeSession.php
if (empty($_SESSION)) {
if (!empty($sessionConfig['ini']) && is_array($sessionConfig['ini'])) {
foreach ($sessionConfig['ini'] as $setting => $value) {
if (ini_set($setting, $value) === false) {
throw new CakeSessionException(__d('cake_dev', 'Unable to configure the session, setting %s failed.', $setting));
}
}
}
}
Everything seems to works fine. Now, I'm asking what is the downside of keeping that snippets commented (in other word, what is that code responsible for)?
As the exception message, the method name and the rest of the code indicates, it configures the session settings, session name, cookie lifetime, save handler, etc...
Your code may run fine, and you should be able to use the PHP session_*() functions instead to configure the settings (the best place for that would probably your bootstrap.php). Also writing a dummy value into $_SESSION seems to prevent the CakeSession::_configureSession() to use ini_set(), so you don't have to modify it.
So this might work, but it shouldn't be necessary to jump through such hoops. There's no need to disable ini_set() in a properly set up shared hosting environment, and personally I'd change the hoster in case they are unable to change this behaviour.
Joomla has a feature where it loads the a minified javascript file and the uncompressed version when the site is in debug mode.
I have named both my files correctly and am include it as follows:
JHtml::_('script', JUri::root() . 'path_to_file/jquery-sortable.js');
When I put the site in debug mode, it does not load the uncompressed file.
However, If I use the following instead, it works fine:
JHtml::_('script', 'path_to_file/jquery-sortable.js');
Now I'm not sure whether this is a bug in Joomla or not, but I cannot find any information online regarding this. I would like to use JURI::root() in the path.
Does anyone have any information on this?
Indeed, if the script URL begins with http, the code that is responsible for including the uncompressed version (i.e, remove the min. segment if such exists or add -uncompressed otherwise) is ignored.
The source for this behavior:
JHtml::includeRelativeFiles() in libraries/cms/html/html.php:298
protected static function includeRelativeFiles($folder, $file, $relative, $detect_browser, $detect_debug)
{
// If http is present in filename
if (strpos($file, 'http') === 0)
{
$includes = array($file);
}
else
//process the script sourch.
}
...
}
Most of the script files, including frameworks, are included as relative paths. I guess that this behavior is meant to prevent remote resources from getting 404ed.
I keep getting this warning:
Instance Method'-fetcherWithRequest:fetcherClass:' not found (return type defaults to 'id')
Here is the code that gives me the warning:
+ (GTMHTTPUploadFetcher *)uploadFetcherWithRequest:(NSURLRequest *)request
fetcherService:(GTMHTTPFetcherService *)fetcherService {
// Internal utility method for instantiating fetchers
GTMHTTPUploadFetcher *fetcher;
if (fetcherService) {
fetcher = [fetcherService fetcherWithRequest:request
fetcherClass:self];
} else {
fetcher = (GTMHTTPUploadFetcher *) [self fetcherWithRequest:request];
}
return fetcher;
}
this is in the GTMHTTPUploadFetcher.m file copyright 2010 version 2.0 mac toolbox
I have looked in the GTMHTTPUploadFetcher.h file for the fetcherClass but didn't find anything.
Has anyone else had this problem and how did you solve it?
Everything works ok and I can upload videos to Youtube I would just like to get rid of this warning.
found the correct method in another .h file found on line. Now everything works fine and I don't get a warning.