未定义的变量:位置

编程入门 行业动态 更新时间:2024-10-25 10:30:07
本文介绍了未定义的变量:位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

对不起球员,我读和搜索在网上,我无法找到这个:(一个解决方案。 如果可以请帮我:)谢谢。

如果我硬code 位置,然后它工作得很好。我已经尝试过这几种不同的方法......

P.S。    我要创建某种图片库AJAX页面锻炼:)我认为这位置变量应该是在单/静态类我猜。我没能尚未测试这个类,但我认为这将只对第一个和最后一个图像总是:)(在Java code这将是很容易做到的:))。

错误:  的通知:未定义的变量:位置在D:\瓦帕\的www \在线11测试\ gethint.php

< PHP 类指数{     私人$位置= 1;     下一个公开函数(){         返回$位置++ ;;     }     公共职能preV(){         返回$ position--;     }      公共功能复位(){         $位置= 1;         返回$地位;     } } $行动= $ _ REQUEST [行动];     $指数= 0; 如果($行动!= 1){     $指数=指数:: preV(); } 其他 {     $指数=指数::接下来的(); } 如果($指数< 1){     $指数= 7; } 如果($指数大于7){     $指数= 1; }     $回应=。< IMG的边界= \0 \SRC = \$指数。JPG \ALT = \$指数。\WIDTH = \500 \高度= \ 334 \>中;  回声$反应;  ?>

解决方案

改变这一行

返回$位置++ ;;

返回$位置++; // 额外 ;

和这样的访问类变量

$这个 - >仓位++; //不是$位置

有关创建静态变量使用静态关键字

私有静态$位置= 1;

有关访问静态变量使用

自:: $地位;

改变这种

如果($行动!= 1){     $指数=指数:: preV(); } 其他 {     $指数=指数::接下来的(); }

$ =中新指数(); 如果($行动!= 1){     $指数= $ IN-> preV(); } 其他 {     $指数= $ IN - >接下来(); }

Sorry guys, I am reading and searching over the web and I cannot find a solution for this :(. If you can please help me :) Thanks.

If I hard code position then it works well. I already tried this on several different ways...

P.S. I have to create some kind of image gallery ajax page for exercise :) I assume this position variable should be in singleton/static class i guess. I was not able to test this class yet, but I think this will work only for first and last image always :) (in java code this would be very easy to do :) ).

Error: Notice: Undefined variable: position in D:\Wamp\www\test\gethint.php on line 11

<?php class Index { private $position=1; public function next(){ return $position++;; } public function prev(){ return $position--; } public function reset(){ $position=1; return $position; } } $action=$_REQUEST["action"]; $index = 0; if($action!=1){ $index=Index::prev(); } else { $index=Index::next(); } if($index < 1){ $index=7; } if($index > 7){ $index=1; } $response="<img border=\"0\" src=\"".$index.".jpg\" alt=\"".$index."\" width=\"500\" height=\"334\">"; echo $response; ?>

解决方案

change this line

return $position++;;

to

return $position++; // extra ;

and access class variable like this

$this->position++; // not $position

for creating static variable use static keyword

private static $position=1;

for accessing static variable use

self::$position;

change this

if($action!=1){ $index=Index::prev(); } else { $index=Index::next(); }

to

$in = new Index(); if($action!=1){ $index= $in->prev(); } else { $index= $in->next(); }

更多推荐

未定义的变量:位置

本文发布于:2023-11-11 10:48:51,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1578210.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:变量   位置   未定义

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!