am getting the following syntax error, unexpected 'public' (T_PUBLIC), expecting end of file when running this code from Microsoft PHP Graph Tutorial.
(https://learn.microsoft.com/en-us/graph/tutorials/php?tutorial-step=1)
public function loadViewData(){
$viewData = [];
// Check for flash errors
if (session('error')) {
$viewData['error'] = session('error');
$viewData['errorDetail'] = session('errorDetail');
}
// Check for logged on user
if (session('userName')) {
$viewData['userName'] = session('userName');
$viewData['userEmail'] = session('userEmail');
$viewData['userTimeZone'] = session('userTimeZone');
}
return $viewData;
}
( I am relatively inexperienced php person, trying to learn laravel and link to Microsoft Graph. There are many tutorials for linking to Microsoft but none of them work as far as I can see, most are out of date. This was my best hope.
Code not working: note line below is one causing problem. If remove 'public;' then no errors are reported in VSCode
i.e. Note in VSCode it reports no errors in the file if public is removed. As soon as you add it back in you get '
As per the the code is correct but you need to check the class of curly brackets properly close or not .
1 ) when you are using the class and no closing curly brackets properly that time it's given error like unexpected 'public' (T_PUBLIC), expecting end of file .
class yourController extends Controller {
public function loadViewData(){
$viewData = [];
// Check for flash errors
if (session('error')) {
$viewData['error'] = session('error');
$viewData['errorDetail'] = session('errorDetail');
}
// Check for logged on user
if (session('userName')) {
$viewData['userName'] = session('userName');
$viewData['userEmail'] = session('userEmail');
$viewData['userTimeZone'] = session('userTimeZone');
}
return $viewData;
}
}
Related
My error: I am facing this issue quite long time and found one solution in stackoverflow but it doesn't work. I need solution to work with laravel , php 7+ and mysql.
It is showing below error:
ErrorException
Trying to get property 'app_layout' of non-object
Error page consists following code and i tried all solutions in stack overflow but no us. I want to show my layout without any error here.
Error in the script\app\Http\Controllers\MainBaseController.php:26
code on the page is : error line highlighted in BOLD below
use Illuminate\Support\Facades\Schema;
use Froiden\Envato\Traits\AppBoot;
class MainBaseController extends Controller
{
public function __construct()
{
parent::__construct();
// Settings
$this->settings = Setting::first();
$this->year = Common::year();
$this->bootstrapModalRight = true;
$this->bootstrapModalSize = 'md';
**$this->siteLayout = $this->settings->app_layout; // top, sidebar**
$this->forbiddenErrorView = 'errors.403';
$this->showFooter = true;
$this->rtl = $this->settings->rtl;
// Status
$this->statusArray = [
'enabled' => __('app.enabled'),
'disabled' => __('app.disabled')
];
// Setting assets path
$allPaths = Common::getFolderPath();
foreach($allPaths as $allPathKey => $allPath)
{
$this->{$allPathKey} = $allPath;
I am placing error part of the code above , if you need any other parts i will provide
I have a Zend2 project running on my localhost with no problems. The app runs perfect. I Uploaded it to my server and now it gets a fatal error but not every time.
Sometimes it says this,
Fatal error: Class name must be a valid object or a string in /home/public_html/vendor/zendframework/zend-stdlib/src/ArrayObject.php on line 230
public function getIterator()
{
$class = $this->iteratorClass;
return new $class($this->storage); // line 230
}
And sometimes it says this,
File
/vendor/zendframework/zend-stdlib/src/ArrayObject.php:184
Message:
Passed variable is not an array or object, using empty array instead
Never both and sometimes it loads perfectly with no problems. The file it references is in the vendor path this is the link,
public function exchangeArray($data)
{
if (!is_array($data) && !is_object($data)) {
throw new Exception\InvalidArgumentException('Passed variable is not an array or object, using empty array instead');
} // Line 184
if (is_object($data) && ($data instanceof self || $data instanceof \ArrayObject)) {
$data = $data->getArrayCopy();
}
if (!is_array($data)) {
$data = (array) $data;
}
$storage = $this->storage;
$this->storage = $data;
return $storage;
}
Any ideas why this would happen on a live server with a zend site but not on a localhost?
I found this post on github which I think it related to ZFCUser
Git Hub Post
Someone in the comments says this,
This issue is caused by the layout.phtml when there is an error. The layout needs to render but it doesn't have $this->url
I have no clue what he is talking about. Is anyone able to shoot me in the right direction?
I can't open my "member" page. I get error: syntax error, unexpected T_IF.
I'm trying to do "Auth check" but I get error like above. Does anyone know how to fix this issue? Additionally, this file is in APPATH/classes/controller/member.php
<?php
class Controller_Member extends Controller_Template {
public $template = 'member/template';
public $is_admin = false;
public function before(){
parent::before
// below is the reason I got error for
if (!Auth::check() and Request::active()->action != 'login') {
Response::redirect('member/login');
}
if (Auth::member(100)){
$this->is_admin = true;
}
View::set_global('is_admin', $this->is_admin);
}
public function action_login(){
Auth::check() and Response::redirect('member');
if (Input::post('username') and Input::post('password')){
$username = Input::post('username');
$password = Input::post('password');
$auth = Auth::instance();
}
}
//ログインフォームの表示
$this->template->title = 'ギアらはここ';
$this->template->content = View::forge('member/form');
}
public function action_logout(){
//ログアウト
$auth = Auth::instance();
$auth->logout();
//'member'にリダイレクト
Response::redirect('member');
}
}
You're missing (); in your parent::before-call. That error you're getting are kind of confusing to beginners. It actually means:
"There's something wrong before this piece of code, because I didn't expect to meet the word Auth here."
So basically, when you get a Syntax-error, start by inspecting the code right before the place where you're getting your error.
You do, however, also have multiple errors further down.
<?php
class Controller_Member extends Controller_Template
{
public $template = 'member/template';
public $is_admin = false;
public function before()
{
parent::before();
// ^^^ Here, you missed the call ( () ) and semicolon ( ; )
// ...
}
public function action_login()
{
Auth::check() and Response::redirect('member');
// ^^ This line does not make sense without an if statement ^^
// Except if it throws exceptions.
}
//...
}
This part is not inside any methods, but directly in the class, and thereby does not make sense either (You must put it inside a function) :
//ログインフォームの表示
$this->template->title = 'ギアらはここ';
$this->template->content = View::forge('member/form');
And right after that, you have another closing bracket }, which will also yield a syntax error. It's unclear where you meant those two lines; in my mind, they don't belong in either of your methods, but it seems like you just need to remove the closing bracket right before the two lines above.
All in all, be sure to indent your code properly, then you'll catch most of these errors.
<?php
class TEST{
public $x=1;
private $y=2;
public function changeA($val){
//$this->x = $val;
echo "X-->".$this->x;
}
private function changeB($val){
//$this->y = $val;
echo "Y-->".$this->y;
}
}
$a = new TEST();
$a->changeA(3);
#
$a->changeB(4);
This is really bugging me, I use all the correct syntax but I got error right on the line I do CLASS test.
Parse error: parse error in file.php on line x
Tested:
-Remove vars, functions, new objects. nothing fix it.
====Updated Code above, but still, the same error.
I think there is something wrong with my php... I am now running all different kind of code, even echo return the same error. I think there is some other trouble with my php setup.
===Last update
I was using Ajax to passing value and write into a php file with 755 and public access. It was seem like a kind of process hiccup. Now it functioning correctly. But the example still, really useful. Well, don't know what is the vote down for, its seem make sense to mark reason for vote down as well like the ones who need to vote to close it. So SO can as least know the reason for the vote down. Interesting right? Someone who actually care about improving this.
Class method definitions are not statements, and therefore should not be terminated with ;.
This means that the }; on lines 11, 16 and 17 should simply be } instead.
On another note, I don't know what version of PHP you're using. I'm using PHP 5.5 and got a very clear message:
Parse error: syntax error, unexpected ';', expecting function (T_FUNCTION) in test.php on line 11
It's always good to practice on simple examples to make its own idea about how it works.
This might help to clarify things.
class test
{
public $x;
private $y;
function __construct() {
echo "-- Constructor --<br/>";
$this->changeX(1);
$this->changeY(2);
echo "-- Exiting Constructor --<br/>";
}
public function changeX($val) {
$this->x = $val;
echo "X-->".$this->x."<br/>"; // for debugging purpose only
}
private function changeY($val) {
$this->y = $val;
echo "Y-->".$this->y."<br/>"; // for debugging purpose only
}
public function changeYprivate($val) {
$this->changeY($val); // can call private method here
}
public function getY() {
return $this->y;
}
}
$objTest = new test();
echo "X is ".$objTest->x." and Y is ".$objTest->getY()."<br/>";
$objTest->changeX(3);
$objTest->x = 10; // ok x is public, it can be modified
$objTest->changeYprivate(4);
// $a->changeY(4); // Error : cannot call this function outside the class !
// $objTest->y = 20; // Error : y is private !
// echo $objTest->y; // Error ! Can't even read y because it's private
echo "X is ".$objTest->x." and Y is ".$objTest->getY()."<br/>";
Output:
-- Constructor --
X-->1
Y-->2
-- Exiting Constructor --
X is 1 and Y is 2
X-->3
Y-->4
X is 10 and Y is 4
I get a strange PHP error after updating my php version to 5.4
This is my function
protected function create() {
//if (VBRIDGE_DEBUG)
//drupal_set_message(__CLASS__ .'::'.__METHOD__);
$path = $this->vbridge_root_path;
$path_vbridge = $path . '/' . VBridge::VBRIDGE_CLASS_PREFIX;
$subclass = $this->getClass();
foreach ($this->_objclass as $objclass) {
if (!$this->createObj($path, $objclass, $subclass)) {
$this->createObj($path_vbridge, $objclass);
}
}
if (self::getStatus()) {
return false;
}
// Set User Session Qookie
//$this->getUser()->setQookie($this->getQookie());
// Set User Session
$this->getUser()->setSession($this->getSession());
$this->getSession()->setQookie($this->getQookie());
//$this->getUser()->setAuth($this->getAuth());
// Set User Pass
$this->getUser()->setPass($this->getPass());
// Set Auth
$this->setAuthMethods();
$this->setAuthStorages();
//
foreach ($this->getConfig() as $config) {
if ($config['#type'] == '#class') {
//createObj($config['#name'], $config['#type'], $config['#class'], $config['#path'], $appData['#config']);
}
}
return true;
}
This is the line that gives
if ($config['#type'] == '#class') {
I've looked at similar questions but haven't figured out how to fix this. Any assistance would be helpful.
Edit: Yes, I did put wrong code up last night. I was very tired after trying to tangle with this.
The error message you've posted doesn't match the line of code you say it originates from. You should get a different error for that, specifically to do with only using variables by reference.
Your code should be
$accounts = user_load_multiple(array(), array('name' => $login));
$account = array_shift($account);
But Drupal already has a helper method for that, so you might as well use it:
$account = user_load_by_name($login);