Include(_once) & require(_once) looks for included files in wrong directory, depending on CWD #17

已關閉
建立於 2018-07-22 16:57:43 +02:00belliash · 7 則評論
擁有者

Aer Information

  • Aer Version (or commit ref): 4c81475afb
  • Operating System: Linux
  • System Architecture (eg. arm, x86_64, ...): x86_64

Your problem description

When relative path is passed as argument to include alike function, it looks for source file in current directory (.). When first source file is opened, it should change working directory to it. This way, script will behave in the same way, independent on CWD.

Example directory structure:

~/
~/binary
~/binary/psharp
~/test.php
~/a.php

test.php:

<?php
    require_once 'a.php';
?>

a.php:

<?php
    echo 'Hello World';
?>

If our current working directory (CWD) is ~/binary and we call ./psharp ../test.php it will not find a.php. However, if we change directory to ~ and call ./binary/psharp test.php it will work just fine.

<!-- 1. Please speak English, this is the language all of us can speak and write. 2. Please take a moment to check that your issue doesn't already exist. 3. Please give all relevant information below for bug reports, because incomplete details will be handled as an invalid report. --> # Aer Information - Aer Version (or commit ref): 4c81475afb - Operating System: Linux - System Architecture (eg. arm, x86_64, ...): x86_64 # Your problem description When relative path is passed as argument to include alike function, it looks for source file in current directory (.). When first source file is opened, it should change working directory to it. This way, script will behave in the same way, independent on CWD. Example directory structure: ~/ ~/binary ~/binary/psharp ~/test.php ~/a.php test.php: <?php require_once 'a.php'; ?> a.php: <?php echo 'Hello World'; ?> If our current working directory (CWD) is ~/binary and we call ./psharp ../test.php it will not find a.php. However, if we change directory to ~ and call ./binary/psharp test.php it will work just fine.
belliash 加入了
bug
標籤 2018-07-22 16:57:43 +02:00
作者
擁有者

IMHO, Aer Interpreter should change CWD to directory containing entry file.

IMHO, Aer Interpreter should change CWD to directory containing entry file.
普通成員

hopefully #16 fix ought to fix it too.

hopefully #16 fix ought to fix it too.
作者
擁有者

Unfortunately not.
What is more, require_once & include_once stopped working.

Unfortunately not. What is more, require_once & include_once stopped working.
普通成員

Hopefully it does now :)

Hopefully it does now :)
作者
擁有者

Yes, functions are working again, however this ticket is not resolved yet.
File inclusion depends on CWD and I believe we have to chdir to realpath of entry file.

Yes, functions are working again, however this ticket is not resolved yet. File inclusion depends on CWD and I believe we have to chdir to realpath of entry file.
devnexen 關閉了這個問題 2018-07-23 15:03:46 +02:00
belliash 重新開放了這個問題 2018-07-23 19:47:20 +02:00
作者
擁有者

This is still not working. In 3ed00e610f, I have fixed the PH7_VM_CONFIG_IMPORT_PATH mechanism. Actually, we just need to get the absolute path of entry file, then obtain realpath and register it into import path.

This is still not working. In 3ed00e610f, I have fixed the PH7_VM_CONFIG_IMPORT_PATH mechanism. Actually, we just need to get the absolute path of entry file, then obtain realpath and register it into import path.
belliash 指派給自己 2018-07-23 22:19:38 +02:00
作者
擁有者

I will take care.

I will take care.
belliash 關閉了這個問題 2018-07-24 08:06:22 +02:00
登入 才能加入這對話。
2 參與者
通知
截止日期
未設定截止日期。
先決條件

未設定先決條件。

參考: aerscript/Aer#17
沒有提供描述。