Tell me more ×
Ask Different is a question and answer site for power users of Apple hardware and software. It's 100% free, no registration required.

I'm having lot of troubles making this call in PHP:

 require_once ( '../interfaces/class-ai1ec-get-data-from-cache.php' );

while if I change to a call like this:

 require_once ( 'interfaces/class-ai1ec-get-data-from-cache.php' );

everything works as expected. I only have this problem on my MacBook Pro. I tried using MAMP and Zend Server but nothing works for me and someone said it's a kind of security restriction.

This is the error message

Warning:
require_once(../interfaces/class-ai1ec-get-data-from-cache.php):
failed to open stream: No such file or directory in
/usr/local/zend/apache2/htdocs/wordpress/wp-content/plugins/all-in-one-event-calendar-premium/app/strategies/get_data_from_cache/class-ai1ec-get-data-from-db-cache.php
on line 3 Fatal error: require_once(): Failed opening required
'../interfaces/class-ai1ec-get-data-from-cache.php'
(include_path='.:/usr/local/zend/share/ZendFramework/library:/usr/local/zend/share/pear')
in
/usr/local/zend/apache2/htdocs/wordpress/wp-content/plugins/all-in-one-event-calendar-premium/app/strategies/get_data_from_cache/class-ai1ec-get-data-from-db-cache.php
on line 3

I tried Zend, Mamp and the internal Apache.

share|improve this question
You should at least post the error message. Also your two code examples go looking for files in a different location, so maybe you are looking in the wrong location in the first example? Finally, what are you currently running? MAMP, Zend or the built-in PHP installation? – Gerry Aug 13 '12 at 16:45
@Gerry posted the error message. i tried with Zend, MAMO and built in and always got the same – Nicola Peluchetti Aug 13 '12 at 17:11
Does the directory/file PHP tries to open (/usr/local/zend...) exist in the first place? – patrix Aug 15 '12 at 18:10

closed as off topic by Mark, patrix, Lauri Ranta, Gerry, Stu Wilson Sep 7 '12 at 21:01

Questions on Ask Different are expected to relate to Apple hardware or software within the scope defined in the FAQ. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about closed questions here.

2 Answers

the base path(s) for require and include is configured in the include path.

files are being loaded relative to that. so, if you prepend your path with .., you're telling php to look for the file one directory level higher.

also, the error message tells you that your include_path includes . which is the current working directory. the cwd relates to the scope (directory) in which the php script is being executed (or has itself been included from).

addition:

in this particular case php looks for the file at the following locations:

  • ../interfaces/class-ai1ec-get-data-from-cache.php
  • /usr/local/zend/share/ZendFramework/interfaces/class-ai1ec-get-data-from-cache.php
  • /usr/local/zend/share/interfaces/class-ai1ec-get-data-from-cache.php

the first one is special as it is relative to your document root (...i guess, because it looks like you're using wordpress).

share|improve this answer
Yes, what i can't get to work is telling php to go one step higher :) – Nicola Peluchetti Aug 13 '12 at 18:05
update the answer - have a look at the addition. – glasz Aug 14 '12 at 16:55
i answered my question with the only thing that made things work :) – Nicola Peluchetti Aug 15 '12 at 11:30

The only way to get things working was using

 require_once( str_replace('//','/',dirname(__FILE__).'/') .'../interfaces/class-ai1ec-get-data-from-cache.php');
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.