Why does php 'use' fail when I put example code into a function? -
having started example code, don't understand why these scenarios don't work.
script of example code called script.php file works when run command line
<?php //script in standalone file: script.php //...define stuff require required_file; use aws\ses\sesclient; //now stuff ?>
when inline contents of script large program fails on 'use' part.
<?php //class-of-bigger-program.php //function called other part of program function foo(){ //paste contents of same script above //...define stuff require required_file; use aws\ses\sesclient;//crash here // stuff } ?>
however when including script in same place of larger program works fine.
<?php //function called other part of program function foo(){ //paste contents of same script above include 'script.php'; } ?>
why case? miss using 'use' command? have found differences between 'use' , 'include' , namespaces hard understand.
why add use in function? if class-of-bigger-program.php
class, should do:
require required_file; use aws\ses\sesclient; class yourclass {...}
Comments
Post a Comment